Click here to Skip to main content
15,895,192 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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");
        }
Posted
Updated 23-Sep-10 4:16am
v2
Comments
Kschuler 23-Sep-10 10:16am    
Edit - I put your code in a code block so it would be easier to read.

You have to update the tables separately. Split out the data and run two updates one on each table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900