Jump to content
Xtreme .Net Talk

save data from two forms into same table in winforms application


Recommended Posts

Guest Ravi Kumar12233
Posted

I have two winforms where form 1 is used to enter data from first seven fields and other forms is used to enter for last three fields , where i have the table stored in MSSQL server , but the problem is whenever i tried to save data in second forms it is getting stored in first row itself instead of the row where the first form is updating , so anyone please help how to link these two forms and get them saved in the same row :

 

below is the code for saving the data in Second form, and images are attached:

 

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace Windows

{

 

public partial class Form2 : Form

{

public Form1()

{

InitializeComponent();

}

 

private void btnInsert_Click(object sender, EventArgs e)

{

SqlConnection con = new SqlConnection(cs);

SqlCommand cmd;

con.Open();

string s="insert into Student values(@p1,@p2,@p3)";

cmd=new SqlCommand(s,con);

cmd.Parameters.AddWithValue("@p1",rejectReason1ComboBox.Text);

cmd.Parameters.AddWithValue("@p2",rejectReason2ComboBox.Text);

cmd.Parameters.AddWithValue("@p3",rejectReason3ComboBox.Text);

cmd.CommandType = CommandType.Text;

int i=cmd.ExecuteNonQuery();

con.Close();

MessageBox.Show(i+ " Row(s) Inserted ");

}

}

}

1627891

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...