ASP.NET学习社区ASP.NET学习区有问有答 打印出的sql语句不完整。为什么呢?

1  /  1  页   1 跳转 查看:170

打印出的sql语句不完整。为什么呢?

打印出的sql语句不完整。为什么呢?

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class UnitGJAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string ID = Request.QueryString["ID"];
        readGJUnit(ID);
    }
    protected void readGJUnit(string ID)
    {
        SqlConnection Conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction);
        Conn.Open();
        string strSql="SELECT top 1 * FROM [AS_UnitInfo] ORDER BY ID DESC";
        SqlCommand cmd = new SqlCommand(strSql,Conn);
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())    //使用while循环,表示从头一直查找到尾
        {
            this.txtAS_FacName.Text = dr["AS_FacName"].ToString();
            this.txtAS_ContactEmail .Text= dr["AS_ContactEmail"].ToString();
            this.txtAS_ContactFax.Text = dr["AS_ContactFax"].ToString();
            this.txtAS_ContactMobile.Text = dr["AS_ContactMobile"].ToString();
            this.txtAS_ContactPots.Text = dr["AS_ContactPots"].ToString();
            this.txtAS_ContactTel.Text = dr["AS_ContactTel"].ToString();
            this .txtAS_FactoryPicture.Text=dr["AS_FactoryPicture"].ToString();
            this .txtAS_History.Text=dr["AS_History"].ToString();
            this.txtAS_Leadorship.Text = dr["AS_Leadorship"].ToString();
            this .txtAS_ProductInfo.Text=dr["AS_ProductInfo"].ToString();
            this.txtAS_ProductStructure.Text = dr["AS_ProductStructure"].ToString();
            this.txtAS_ProductTeam.Text = dr["AS_ProductTeam"].ToString();
            this.txtAS_ResearchPicture.Text = dr["AS_ResearchPicture"].ToString();
            this.txtAS_ResearchTeam.Text = dr["AS_ResearchTeam"].ToString();
            this.txtAS_SaleMode.Text = dr["AS_SaleMode"].ToString();
            this .txtAS_SaleTeam.Text=dr["AS_SaleTeam"].ToString();
            this.txtAS_YearSales.Text = dr["AS_YearSales"].ToString();
            this.txtAS_Yield.Text = dr["AS_Yield"].ToString();
            this.hidUnitID.Value = ID;
        }
        dr.Close();
        cmd.Dispose();
        Conn.Close();
    }
    protected void saveGJUnit()
    {
        string strUnitID = this.hidUnitID.Value;
        string strAS_ContactEmail = this.txtAS_ContactEmail.Text;
        string strAS_Contact = this.txtAS_Contact.Text;
        string strAS_ContactFax= this.txtAS_ContactFax.Text;
        string strAS_ContactMobile= this.txtAS_ContactMobile.Text;
        string strAS_ContactPots = this.txtAS_ContactPots.Text;
        string strAS_ContactTel = this.txtAS_ContactTel.Text;
        string strAS_FactoryPicture = this.txtAS_FactoryPicture.Text;
        string strAS_History = this.txtAS_History.Text;
        string strAS_Leadorship = this.txtAS_Leadorship.Text;
        string strAS_ProductInfo = this.txtAS_ProductInfo.Text;
        string strAS_ProductStructure = this.txtAS_ProductStructure.Text;
        string strAS_ProductTeam = this.txtAS_ProductTeam.Text;
        string strAS_ResearchPicture = this.txtAS_ResearchPicture.Text;
        string strAS_ResearchTeam = this.txtAS_ResearchTeam.Text;
        string strAS_SaleMode = this.txtAS_SaleMode.Text;
        string strAS_SaleTeam = this.txtAS_SaleTeam.Text;
        string strAS_YearSales = this.txtAS_YearSales.Text;
        string strAS_Yield = this.txtAS_Yield.Text;
        string strSql = "UPDATE [AS_UnitInfo] SET";
       
        if (strAS_Contact != "") { strSql += ",AS_Contact='"+strAS_Contact+"'"; }
        if (strAS_ContactEmail != "") { strSql += ",AS_ContactEmail='" + strAS_ContactEmail + "'"; }
        if (strAS_ContactFax != "") { strSql += ",AS_ContactFax='" + strAS_ContactFax + "'"; }
        if (strAS_ContactMobile != "") { strSql += ",AS_ContactMobile='" + strAS_ContactMobile + "'"; }
        if (strAS_ContactPots != "") { strSql += ",AS_ContactPots='" + strAS_ContactPots + "'"; }
        if (strAS_ContactTel != "") { strSql += ",AS_ContactTel='" + strAS_ContactTel + "'"; }
        if (strAS_FactoryPicture != "") { strSql += ",strAS_FactoryPicture='" + strAS_FactoryPicture + "'"; }
        if (strAS_History != "") { strSql += ",AS_History='" + strAS_History + "'"; }
        if (strAS_Leadorship != "") { strSql += ",AS_Leadorship='" + strAS_Leadorship + "'"; }
        if (strAS_ProductInfo != "") { strSql += ",AS_ProductInfo='" + strAS_ProductInfo + "'"; }
        if (strAS_ProductStructure != "") { strSql += ",AS_ProductStructure='" + strAS_ProductStructure + "'"; }
        if (strAS_ProductTeam != "") { strSql += ",AS_ProductTeam='" + strAS_ProductTeam + "'"; }
        if (strAS_ResearchPicture != "") { strSql += ",AS_ResearchPicture='" + strAS_ResearchPicture + "'"; }
        if (strAS_SaleMode != "") { strSql += ",AS_SaleMode='" + strAS_SaleMode + "'"; }
        if (strAS_SaleTeam != "") { strSql += ",AS_SaleTeam='" + strAS_SaleTeam + "'"; }
        if (strAS_YearSales != "") { strSql += ",AS_YearSales='" + strAS_YearSales + "'"; }
        if (strAS_Yield != "") { strSql += ",AS_Yield='" + strAS_Yield + "'"; }
        strSql = strSql.Replace("SET,", "SET ");
        strSql = strSql + " where [ID]=" + strUnitID;
        Response.Write(strSql);
        Response.End();
        SqlCommand cmd = new SqlCommand();
        using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
        {
            //打开连接
            conn.Open();
            //调用执行方法,因为没有参数,所以最后一项直接设置为null
            //SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql, null);
            //strSql += " select @@IDENTITY AS 'ID'";
            object myobj = SqlHelper.ExecuteScalar(conn, CommandType.Text, strSql, null);
            //return myobj.ToString();
        }
    }
    protected void btnSaveGJUnit_Click(object sender, EventArgs e)
    {
        saveGJUnit();
    }
}


当我直接保存按钮的时候,打印出的sql语句不完整。为什么呢?
 

回复:打印出的sql语句不完整。为什么呢?

你调试进去,一步一步看看。
语句多了,看着有点烦
http://www.Aspx1.Com
请帮忙宣传Aspx1 , Aspx1是ASP.NET学习者的家园 , 适宜长期居住.
 

回复:打印出的sql语句不完整。为什么呢?

呵呵,调试的时候出来了,
如果用了readGJUnit(string ID)
函数则可以打印出正常的sql但是传值没有
如果不用readGJunit函数 则sql语句不完整,
估计是
传地址和传值的问题。。
本帖被评分 1 次
 
1  /  1  页   1 跳转

版权所有 ASP.NET学习门户 2.0.1214   Sitemap  

返顶部