for login table
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into login(username,empid)values (@username,@empid)";
SqlCommand cmd = new SqlCommand(insertQuery, conn);
cmd.Parameters.AddWithValue("@username", TextBox1.Text);
cmd.Parameters.AddWithValue("@empid", TextBox2.Text);
cmd.ExecuteNonQuery();
Session["username"] = TextBox1.Text;
Session["empid"] = TextBox2.Text;
conn.Close();
for table11 table
protected void Submit_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into table11(ans,ans1,ans2,ans3,ans4,username,password) values (@ans,@ans1,@ans2,@ans3,@ans4,@username,@password)";
SqlCommand cmd = new SqlCommand(insertQuery, conn);
cmd.Parameters.AddWithValue("ans", RadioButtonList1.SelectedItem.Text);
cmd.Parameters.AddWithValue("ans1", RadioButtonList2.SelectedItem.Text);
cmd.Parameters.AddWithValue("ans2", RadioButtonList3.SelectedItem.Text);
cmd.Parameters.AddWithValue("ans3", RadioButtonList4.SelectedItem.Text);
cmd.Parameters.AddWithValue("ans4", RadioButtonList5.SelectedItem.Text);
cmd.Parameters.AddWithValue("username", Session["username"].ToString());
cmd.Parameters.AddWithValue("empid", Session["empid"].ToString());
cmd.ExecuteNonQuery();
Response.Write("You Submitted Sucessfully!");
conn.Close();
}
catch (Exception ex)
{
}
}
What I have tried:
for username I have made table login.
and in table11 I want the username and empid using sessions
I'm unable to store username, empid into the table .
please provide me with the correct code to store the username and empid into table 11