Hello Friends
I have two tables in database named as student and student1.
Student Table :
ID (Primary key),Name,Father Name,Phone No.
Student1 Table :
ID (Foreign Key),Department Name
and cs Code file is given Below which is coded by me.
string Strsql = select * from student; Select * from student1;
Connection.sqldataadapter = new SqlDataAdapter(Strsql, Connection.sqlconnection);
Connection.dataset = new DataSet();
Connection.sqldataadapter.Fill(Connection.dataset);
Connection.dataset.Tables[0].TableName = Student;
Connection.dataset.Tables[1].TableName = Student1;
Connection.sqldataadapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
dgvStudent.DataSource = Connection.dataset.Tables[0];
Connection.sqlcommandbuilder = new SqlCommandBuilder(Connection.sqldataadapter);
On Insert Button Click:
DataRow dr = Connection.dataset.Tables[0].NewRow();
dr["ID"] = textBox1.Text;
dr["Name"] = textBox2.Text;
dr["FatherName"] = textBox3.Text;
dr["PhoneNo"] = textBox4.Text;
Connection.dataset.Tables[0].Rows.Add(dr);
DataRow dr1 = Connection.dataset.Tables[1].NewRow();
dr1["ID"] = textBox1.Text;
dr1["DepartmentName"] = textBox5.Text;
Connection.dataset.Tables[1].Rows.Add(dr1);
textBox1.Text="";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
On Update Button Click :
DataRow dr = Connection.dataset.Tables[Student].Rows[index];
DataRow dr1 = Connection.dataset.Tables[Student1].Rows[index];
dr[ID] = textBox1.Text;
dr[Name] = textBox2.Text;
dr[FatherName] = textBox3.Text;
dr[PhoneNo] = textBox4.Text;
dr1[DepartmentName] = textBox5.Text;
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
On Submit Button Click : this is the button on which my dataadapter is updated but it gives some error. it fill the data in student table but it doesn't fill data in student1.
Connection.sqldataadapter.Update(Connection.dataset.Tables[0]);
Connection.sqldataadapter.Update(Connection.dataset.Tables[1]);
Missing the DataColumn 'NAME' in the DataTable 'Student1' for the SourceColumn 'NAME'.
pls Help me out asap. Thanks in advance for solving my problem......................