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 insertion
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection con;
SqlCommand cmd;
SqlParameter p1,p2,p3;
private void Form1_Load(object sender, EventArgs e)
{
cmd = new SqlCommand("insert into emp values (@a,@b,@c)");
con = new SqlConnection(@"Data Source= . ;Initial Catalog=ducat;Integrated Security=True");
cmd.Connection = con;
p1 = new SqlParameter();
p2 = new SqlParameter();
p3 = new SqlParameter();
p1.ParameterName = "@a";
p2.ParameterName = "@b";
p3.ParameterName = "@c";
p1.SqlDbType = SqlDbType.Int;
p2.SqlDbType = SqlDbType.VarChar;
p3.SqlDbType = SqlDbType.VarChar;
p2.Size = 50;
p3.Size = 50;
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
cmd.Parameters.Add(p3);
}
private void button1_Click(object sender, EventArgs e)
{
p1.Value = textBox1.Text;
p2.Value = textBox2.Text;
p3.Value = textBox3.Text;
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Inserted");
con.Close();
}
}
}