Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

C#
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 :

C#
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.

C#
Connection.sqldataadapter.Update(Connection.dataset.Tables[0]);
Connection.sqldataadapter.Update(Connection.dataset.Tables[1]); // on this point it gives error which is given below :



Missing the DataColumn 'NAME' in the DataTable 'Student1' for the SourceColumn 'NAME'.


pls Help me out asap. Thanks in advance for solving my problem......................
Posted
Updated 1-Dec-11 19:43pm
v2
Comments
[no name] 2-Dec-11 1:43am    
EDIT: added "pre" and "b" tags

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