Code
Code
Create table SD
(Sid nvarchar(10),
Sname nvarchar(50),
Gender nvarchar(30),
Address nvarchar(50)
)
Select * from SD
using
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;
System.Data.SqlClient;
namespace Sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label3_Click(object sender, EventArgs e)
{
}
SqlConnection con = new SqlConnection("uid=sa;password=123;database=Guru");
private void btnsubmit_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into SD
values('"+txtsid.Text+"','"+txtsname.Text+"','"+cmbgender.Text+"','"+txtaddress.Text+"')",con);
cmd.ExecuteNonQuery();
MessageBox.Show("Successfully Submited...");
con.Close();
txtsid.Text = txtsname.Text = cmbgender.Text = txtaddress.Text = null;
}
private void button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("update SD set Address='"+txtaddress.Text+"'
where SId='"+txtsid.Text+"'",con);
cmd.ExecuteNonQuery();
MessageBox.Show("updated...");
con.Close();
txtsid.Text = txtaddress.Text = null;
}
private void button2_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("delete from SD where
SId='"+txtsid.Text+"'",con);
cmd.ExecuteNonQuery();
MessageBox.Show("Deleted...");
con.Close();
txtsid.Text = null;
}
}
}