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

sda.SelectCommand.Connection = con 提示 未将对象引用设置到对象的实例
提示 未将对象引用设置到对象的实例。 sda.SelectCommand.Connection = con;错误,一下是源代,怎么解决
  sda.SelectCommand.Connection = con;

C# code

            SqlConnection con = Ares.WebSite.App_Code.DB.CreateConn();
            con.Open();
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand.Connection = con;
            sda.SelectCommand.CommandText = "select * from M_SalesTab";

            DataSet ds = new DataSet();
            sda.Fill(ds);
            Response.Write(ds.Tables[0].Rows[0][1].ToString());



------解决方案--------------------
引用
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand.Connection = con;
sda.SelectCommand.CommandText = "select * from M_SalesTab";

------解决方案--------------------
探讨

引用
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand.Connection = con;
sda.SelectCommand.CommandText = "select * from M_SalesTab";

我怎么感觉这里少了一步 sda.SelectCommand = new SqlCommand();
……