然后我的一个DataGridView.DataSource是其中的一个表。
为什么对DataGridView修改后,然后更新,数据库中没有反应using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using dataSetTest2.DeviceBasesDataSetTableAdapters;namespace dataSetTest2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
BASE_INFORMATIONTableAdapter tableAdapter;
DeviceBasesDataSet dataSet; private void Form1_Load(object sender, EventArgs e)
{
dataSet = new DeviceBasesDataSet(); tableAdapter = new BASE_INFORMATIONTableAdapter();
tableAdapter.Fill(dataSet.BASE_INFORMATION); dataGridView1.DataSource = dataSet.BASE_INFORMATION;
} private void buttonUpdate_Click(object sender, EventArgs e)
{
tableAdapter.Update(dataSet.BASE_INFORMATION);
}
}
}
为什么对DataGridView修改后,然后更新,数据库中没有反应using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using dataSetTest2.DeviceBasesDataSetTableAdapters;namespace dataSetTest2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
BASE_INFORMATIONTableAdapter tableAdapter;
DeviceBasesDataSet dataSet; private void Form1_Load(object sender, EventArgs e)
{
dataSet = new DeviceBasesDataSet(); tableAdapter = new BASE_INFORMATIONTableAdapter();
tableAdapter.Fill(dataSet.BASE_INFORMATION); dataGridView1.DataSource = dataSet.BASE_INFORMATION;
} private void buttonUpdate_Click(object sender, EventArgs e)
{
tableAdapter.Update(dataSet.BASE_INFORMATION);
}
}
}
想知道有没有什么方便的方法
我想在修改的时候把DataGridView中新添加的数据写到DataTable中
晕
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using dataSetTest2.DeviceBasesDataSetTableAdapters;
using System.Data.OleDb;namespace dataSetTest2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
BASE_INFORMATIONTableAdapter tableAdapter;
DeviceBasesDataSet dataSet; private void Form1_Load(object sender, EventArgs e)
{
dataSet = new DeviceBasesDataSet(); tableAdapter = new BASE_INFORMATIONTableAdapter();
tableAdapter.Fill(dataSet.BASE_INFORMATION); dataGridView1.DataSource = dataSet.BASE_INFORMATION;
} private void buttonUpdate_Click(object sender, EventArgs e)
{
DataRow dataRow = dataSet.BASE_INFORMATION.NewRow(); dataRow[0] = "2100";
dataRow[1] = "Ericsson";
dataRow[2] = "Misc";
dataSet.BASE_INFORMATION.Rows.Add(dataRow); dataSet.AcceptChanges();
tableAdapter.Update(dataSet);
} }
}