日期:2014-05-18  浏览次数:21247 次

Fill: selectCommand.Connection 属性尚未初始化
C# code

SqlConnection thisConnection = new SqlConnection(
               @"Server=CVRE1WTZRSTAGNW\SQLSERVER2008;Integrated Security=True;Database=gdbranch;");
            thisConnection.Open();
           
            SqlCommand cmd=new SqlCommand();
            SqlDataAdapter ada = new SqlDataAdapter();
            System.Data.DataTable dataTable = new System.Data.DataTable();
           
            cmd.CommandText = @"select a.branchid,a.pkey,a.pno,a.ptime,a.pmemo,a.useid,b.pbarcode,sum(qty) from " +
                @"pdacheck a inner join pdacheckd b on a.pkey=b.pkey";
            ada.SelectCommand = cmd;
            ada.Fill(dataTable);
            this.dgData.DataSource = dataTable;



上面代码会有这个提示,请问是哪里不对,谢谢

------解决方案--------------------
添一句
cmd.Connection = thisConnection;