R
Ravi Kumar12233
Guest
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 ");
}
}
}
Continue reading...
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 ");
}
}
}
Continue reading...