问题描述
我在Form9里放入了一个DataGridView控件,然后加了个Button按钮,但运行时数据库里的东西能显示出来,但直接在控件里修改数据后数据库里没有变化,为什么啊??求各位大神解答,小弟新新新新手。。。代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.OleDb;namespace水准网平差{publicpartialclassForm9:Form{publicForm9(){InitializeComponent();}privatevoidForm9_Load(objectsender,EventArgse){//TODO:这行代码将数据加载到表“自由网平差DataSet1.表2”中。您可以根据需要移动或移除它。this.表2TableAdapter.Fill(this.自由网平差DataSet1.表2);strings1="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=D:\VisualStudio2005\新建文件夹\水准网平差\水准网平差\自由网平差.mdb";OleDbConnectionconn=newOleDbConnection(s1);conn.Open();strings2="Select*From表2";OleDbDataAdapterda=newOleDbDataAdapter(s2,s1);DataSetds=newDataSet();da.Fill(ds,"表2");BindingSourcebindingSource1=newBindingSource();bindingSource1.DataSource=ds;bindingSource1.DataMember="表2";dataGridView1.DataSource=bindingSource1;conn.Close();}privatevoidbutton1_Click(objectsender,EventArgse){if(this.自由网平差DataSet1.HasChanges()){this.表2TableAdapter.Update(this.自由网平差DataSet1);//this.表2TableAdapter.Fill(this.自由网平差DataSet1.表2);}}
解决方案
解决方案二:
本帖最后由 caozhy 于 2011-06-06 19:20:16 编辑
解决方案三:
Thankyou~Letmehaveatry~~