sqlCommand1.Connection.Open(); //不要
更改为在初始化
SqlCommand sqlCommand1=new (strCmd,sqlConnection1);

解决方案 »

  1.   

    string  strConn="server=xw;uid=sa;pwd=sa;database=Car";  
                                       sqlConnection1.ConnectionString=strConn;  
                                       sqlConnection1.Open();  
    我看应该没有多大问题,不知是不是其它的原因呢??请教!!
                             
      

  2.   

    这样写,放在strCmd赋值语句后面
    string strConn="server=xw;uid=sa;pwd=sa;database=Car";
    sqlConnection1.ConnectionString=strConn;
    SqlCommand sqlCommand1=new (strCmd,sqlConnection1);
    sqlConnection1.Open();
    sqlCommand1.ExecuteNonQuery();
      

  3.   

    sqlConnection1.Open();//你在这一句已经打开了
    ............................................................
    sqlCommand1.CommandText=cmd;
    sqlCommand1.Connection.Open();//这一句就不用写了,最好将上一个sqlConnection1.Open();写到这里
    sqlCommand1.ExecuteNonQuery();
    sqlCommand1.Connection.Close();//这里就改成sqlConnection1.Close();
      

  4.   

    我是采用的模板绑定的数据,是采取直接将SqlCommand直接拖放在DataGrid下:
    故前面已有申明的
    namespace MyCharu
    {
    /// <summary>
    /// 承包信息维护 的摘要说明。
    /// </summary>
    public class 承包信息维护 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
    protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
    protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
    protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
    protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
    protected System.Data.SqlClient.SqlConnection sqlConnection1;
    protected MyCharu.xwDataSet1 xwDataSet11;
    protected System.Data.SqlClient.SqlCommand sqlCommand1;
    public Hashtable RbListIndex;
    public Hashtable DrpListIndex;
    protected System.Web.UI.WebControls.ImageButton ImageButton1;
    protected System.Web.UI.WebControls.Label Label8;
    static int k=1;
      

  5.   

    TextBox TextBox1=(TextBox)e.Item.FindControl("TextBox1");
    改为
    TextBox TextBox1=(TextBox)e.Item.Cells[数字].FindControl("TextBox1");
      

  6.   

    TextBox TextBox1=(TextBox)e.Item.FindControl("TextBox1");
    改为
    TextBox TextBox1=(TextBox)e.Item.Cells[数字].FindControl("TextBox1");
    ???为什么要改为数字呢??
      

  7.   

    请问一下采用这种方式有什么问题吗: 
      sqlCommand1.Connection.Open();   
     
      sqlCommand1.Connection.Close();   
      

  8.   

    sqlCommand1.Connection.Open()语法都没有错,就是上面你已经打开了一次了,再打开可能会出错了。要不你把sqlConnection.Open()注释掉试试。
      

  9.   

    请问一下采用这种方式有什么问题吗:    
       sqlCommand1.Connection.Open();        
       
       sqlCommand1.Connection.Close();