首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

代码:不知道错在那会儿

2011-12-24 
代码:不知道错在那儿privatevoidbutton3_Click(objectsender,EventArgse){SqlConnectionSqlconnewSqlConn

代码:不知道错在那儿
private   void   button3_Click(object   sender,   EventArgs   e)
                {
                        SqlConnection   Sqlcon   =   new   SqlConnection(connection);

                        SqlDataAdapter   Sda   =   new   SqlDataAdapter( "select   *   from   ts ",Sqlcon);

                        DataSet   Ds=   new   DataSet();

                       

                        //这一行通不过
                        //提示错误为:未将对象引用设置到对象的实例。
                        Ds.Tables[ "ts "].Rows[0].Delete();

                        Sda.Update(Ds);

                       

                }

[解决办法]
Ds 里面没数据当然报错
[解决办法]
Sda.Fill(Ds, "ts ");
[解决办法]
不指定表名的话
Sda.Fill(Ds);
Ds.Tables[0].Rows[0].Delete();
[解决办法]
private void button3_Click(object sender, EventArgs e)
{
SqlConnection Sqlcon = new SqlConnection(connection);

SqlDataAdapter Sda = new SqlDataAdapter( "select * from ts ",Sqlcon);

SqlCommandBuilder cmb = new SqlCommandBuilder(Sda);//加这句

Sda.DeleteCommand = cmb.GetDeleteCommand();//加这句

DataSet Ds= new DataSet();

Sda.Fill(Ds, "ts ");


Ds.Tables[0].Rows[0].Delete();

错误: //当传递具有已删除行的 DataRow 集合时,更新要求有效的 DeleteCommand。
Sda.Update(Ds, "ts ");



}

热点排行