1 Replies - 1119 Views - Last Post: 03 August 2013 - 12:33 AM Rate Topic: -----

#1 boy89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-August 13

problem in solving if i have a single form&want to insert in two t

Posted 03 August 2013 - 12:18 AM

SqlConnection con = new SqlConnection(@"Data Source=SHANT-HP\SQLEXPRESS;Initial Catalog=volunteer0;Integrated Security=True");
SqlCommand cmd = new SqlCommand("insert into PersonalDetails1 values(@volunteerid,@fullname,@dateofbirth,@nationality,@phoner,@mobile,@address,@emailid,@schoolcollege)",con);
cmd.Parameters.AddWithValue("@volunteerid", TextBox1.Text);
cmd.Parameters.AddWithValue("@fullname",TextBox2.Text);
cmd.Parameters.AddWithValue("@dateofbirth",TextBox3.Text);
cmd.Parameters.AddWithValue("@nationality",TextBox4.Text);
cmd.Parameters.AddWithValue("@phoner",TextBox5.Text);
cmd.Parameters.AddWithValue("@mobile",TextBox6.Text);
cmd.Parameters.AddWithValue("@address",TextBox13.Text);
cmd.Parameters.AddWithValue("@emailid",TextBox7.Text);
cmd.Parameters.AddWithValue("@schoolcollege",TextBox8.Text);
con.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Response.Write("Record is inserted");
}
con.Close();
till now its working for insertion into 1st table i.e.Personaldetails
Now i have one more table of parentsdetails which has 4 fields what and where i should write insert code for this.Hope to get some response soon
thanks guys

Is This A Good Question/Topic? 0
  • +

Replies To: problem in solving if i have a single form&want to insert in two t

#2 boy89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-August 13

Re: problem in solving if i have a single form&want to insert in two t

Posted 03 August 2013 - 12:33 AM

View Postboy89, on 03 August 2013 - 12:18 AM, said:

SqlConnection con = new SqlConnection(@"Data Source=SHANT-HP\SQLEXPRESS;Initial Catalog=volunteer0;Integrated Security=True");
SqlCommand cmd = new SqlCommand("insert into PersonalDetails1 values(@volunteerid,@fullname,@dateofbirth,@nationality,@phoner,@mobile,@address,@emailid,@schoolcollege)",con);
cmd.Parameters.AddWithValue("@volunteerid", TextBox1.Text);
cmd.Parameters.AddWithValue("@fullname",TextBox2.Text);
cmd.Parameters.AddWithValue("@dateofbirth",TextBox3.Text);
cmd.Parameters.AddWithValue("@nationality",TextBox4.Text);
cmd.Parameters.AddWithValue("@phoner",TextBox5.Text);
cmd.Parameters.AddWithValue("@mobile",TextBox6.Text);
cmd.Parameters.AddWithValue("@address",TextBox13.Text);
cmd.Parameters.AddWithValue("@emailid",TextBox7.Text);
cmd.Parameters.AddWithValue("@schoolcollege",TextBox8.Text);
con.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Response.Write("Record is inserted");
}
con.Close();
till now its working for insertion into 1st table i.e.Personaldetails....I have set volunteerid primary key and in parents details table i have that primary key as foreign key.
Now i have one more table of parentsdetails which has 4 fields what and where i should write insert code for this.Hope to get some response soon
thanks guys

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1