Category >
WINFORMS
|| Published on :
Sunday, November 22, 2020 || Views:
1277
||
Create a windows form to insert employee information in table
Here Pawan Kumar will explain how to Create a windows form to insert employee information in table
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace stuinformation
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DBname;Integrated Security=True;Pooling=False");
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
SqlCommandBuilder cmb;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e){
}
private void Insert_Click(object sender, EventArgs e)
{
ds.Clear();
string str = "Select * from Emp";
SqlDataAdapter da = new SqlDataAdapter(str, con);
da.Fill(ds);
cmb = new SqlCommandBuilder(da);
DataRow dr = ds.Tables[0].NewRow();
dr[0] = textBox1.Text;
dr[1] = textBox2.Text;
dr[2] = textBox6.Text;
dr[3] = textBox3.Text;
dr[4] = textBox4.Text;
dr[5] = textBox5.Text;
ds.Tables[0].Rows.Add(dr);
da.Update(ds);
MessageBox.Show("Record insert");
}
}
}