无法从网格视图将数据更新到数据库
我的数据库中有两个表.
INV_HEAD和DN_HEAD
表格在下面的链接中给出
http://www.freeimagehosting.net/uploads/7dda8cd2c7.jpg [
在网格视图中,我想输入LR_NO和LR_DT的数据(其中为null)
当我更新数据时,我得到的错误数据无法在两个表中进行更新.
谁能帮我更新数据..
无需在DN_HEAD中的2个表中进行更新就足够了
在这里输入我的代码
I have two tables in my data base .
INV_HEAD and DN_HEAD
tables are given in below link
http://www.freeimagehosting.net/uploads/7dda8cd2c7.jpg[^]]
I have combined two tables by "inner join" and show the data in grid view where LR_NO is null.
in the grid view I want to enter data of LR_NO and LR_DT (where null)
when i am updating data I am getting error data can not be updated in two tables.
can any one help me to update data ..
no need to update in 2 table update in DN_HEAD is enough
HERE MY CODE
public partial class Form2 : Form
{
SqlConnection con;
SqlDataAdapter da1;
SqlCommandBuilder cb;
DataSet ds;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
con = new SqlConnection("User Id=sa;Password=123;database=amar");
da1 = new SqlDataAdapter("SELECT dbo.INV_HEAD.INV_NO, dbo.INV_HEAD.INV_DT, dbo.DN_HEAD.DN_NO, dbo.DN_HEAD.DN_DT, dbo.DN_HEAD.LR_NO, dbo.DN_HEAD.LR_DT FROM dbo.INV_HEAD INNER JOIN dbo.DN_HEAD ON dbo.INV_HEAD.DN_NO = dbo.DN_HEAD.DN_NO where LR_DT IS NULL", con);
ds = new DataSet();
cb = new SqlCommandBuilder(da2);
da1.Fill(ds, "DN_HEAD,INV_HEAD");
dataGridView1.DataSource = ds.Tables["DN_HEAD,INV_HEAD"];
}
private void button1_Click(object sender, EventArgs e)
{
da1.Update(ds, "DN_HEAD,INV_HEAD");
MessageBox.Show("data saved");
}
您必须分别更新表.拆分数据并在每个表上运行两次更新.
You have to update the tables separately. Split out the data and run two updates one on each table.
这是我的问题
http://www.freeimagehosting.net/][img= http://www.freeimagehosting.net/uploads/c6bd177c60.jpg [
here is my problem
http://www.freeimagehosting.net/][img=http://www.freeimagehosting.net/uploads/c6bd177c60.jpg[^]