标题:c# 修改错误
只看楼主
hybshanghai
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-7-13
结帖率:0
 问题点数:0 回复次数:1 
c# 修改错误
private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                int a = this.dataGrid1.CurrentCell.RowNumber;
                string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\c#\\book.mdb";
                OleDbConnection myConn = new OleDbConnection(strCon);
                myConn.Open();
                DataSet myDataSet = new DataSet();
                OleDbCommand command = new OleDbCommand("SELECT * FROM book order by 编号 ", myConn);
                OleDbDataAdapter ads = new OleDbDataAdapter(command);
                ads.Fill(myDataSet);
                string strCom = "UPDATE book set 书名='" + myDataSet.Tables["book"].Rows[a][1] + "',作者='" + myDataSet.Tables["book"].Rows[a][2] + "',价格=" + myDataSet.Tables["book"].Rows[a][3] + ",书架号=" + myDataSet.Tables["book"].Rows[a][4] + " where 编号=" + myDataSet.Tables["book"].Rows[a][0] +"";
                OleDbCommand inst = new OleDbCommand(strCom, myConn);
                inst.ExecuteNonQuery();
                OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT *FROM book order by 编号", myConn);
                myDataSet.Clear();
                myCommand.Fill(myDataSet, "book");
                this.dataGrid1.DataSource = myDataSet.Tables["book"];
                myConn.Close();
            }
            catch (Exception x)
            {
                MessageBox.Show("错误" + x.ToString(), "error"
);
            }
        }
搜索更多相关主题的帖子: command private 
2014-07-14 09:57
小财袅
Rank: 2
等 级:论坛游民
威 望:2
帖 子:7
专家分:50
注 册:2014-7-12
得分:0 
myDataSet.Tables["book"]改成myDataSet.Tables[0]
2014-07-14 11:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-434007-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.106489 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved