TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kishore Konatham
NA
63
7.6k
Save data entered from two forms
Aug 26 2019 12:23 AM
Hi everyone,
I've tried to save details in a data table from two winforms. It is saving form1 data in 1st row and form2 data in 2nd row. But i want it to save in a single row. Can you guys suggest me how?
//FORM1 CODE
private void button1_Click(object sender, EventArgs e)
{
string c = @"Data Source=mysql; Initial Catalog=SampleDB; Integrated Security=True";
Form2 f2 = new Form2();
SqlConnection con = new SqlConnection(c);
con.Open();
SqlCommand cmd = new SqlCommand("studentdetails", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name",txtName.Text.Trim());
cmd.Parameters.AddWithValue("@Contact",txtContact.Text.Trim());
cmd.Parameters.AddWithValue("@Email", f2.txtEmail.Text.Trim());
cmd.Parameters.AddWithValue("@Address", f2.txtAddress.Text.Trim());
cmd.ExecuteNonQuery();
MessageBox.Show("Details Saved..!");
}
private void button2_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}
//FORM2 CODE
private void button1_Click(object sender, EventArgs e)
{
string c = @"Data Source=mysql; Initial Catalog=SampleDB; Integrated Security=True";
Form1 f1=new Form1();
SqlConnection con = new SqlConnection(c);
con.Open();
SqlCommand cmd = new SqlCommand("studentdetails", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name",f1.txtName.Text.Trim() );
cmd.Parameters.AddWithValue("@Contact",f1.txtContact.Text.Trim());
cmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim());
cmd.Parameters.AddWithValue("@Address", txtAddress.Text.Trim());
cmd.ExecuteNonQuery();
MessageBox.Show("Details Saved..!");
}
Reply
Answers (
5
)
Where is Basic Page In VS 2019?
Overwriting the same file each loop.