回 帖 发 新 帖 刷新版面

主题:各位帮帮忙  侃侃是哪里

string StrSQL="DELETE FROM gqsz WHERE  xh='"+this.listView1.SelectedItems [0].Text.Trim()+"'";
     this.sqlCommand1.CommandText=StrSQL;
     this.sqlCommand1.Connection=this.con;
    //打开数据库连接
    this.con.Open();
    //执行SQL命令
    this.sqlCommand1.ExecuteNonQuery();
    //关闭连接
    this.con.Close();
    //更新数据集
    this.dataSet1.Tables["gqsz"].Rows[this.MyBind.Position].BeginEdit();
    this.dataSet1.Tables["gqsz"].Rows[this.MyBind.Position].EndEdit();                
    this.dataSet1.AcceptChanges();
    this.SqlDataAdapter1.Fill(this.dataSet1,"gqsz");
    this.MyBind.Position=this.MyBind.Count;

    MessageBox.Show("此操作将会删除选定的歌曲","信息提 示",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1);



错误显示:未将对象引用设置到对象实例。

小弟刚学,很菜
是哪里应该怎么写!!!!万分感谢!!!!!

回复列表 (共2个回复)

沙发

//关闭连接
    this.con.Close();

这个已经关闭了,你后面用到了this.SqlDataAdapter1.Fill当然会出错了

板凳

To 楼上:

Adapter会自动开启和关闭连接。

应该不是这个问题。

我来回复

您尚未登录,请登录后再回复。点此登录或注册