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 WindowsFormsApplication3
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection("Data Source=ARNAV;Initial Catalog=Mrudu;User ID=sa;Password=manager");
SqlDataAdapter da;
DataSet ds=new DataSet();
SqlCommandBuilder cbd;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DataRow drow = ds.Tables[0].NewRow();
drow[0] = textBox1.Text;
drow[1] = textBox2.Text;
ds.Tables[0].Rows.Add(drow);
cbd = new SqlCommandBuilder(da);
da.Update(ds, "Cust");
//da = new SqlDataAdapter("insert into Cust values("+textBox1.Text+",'"+textBox2.Text+"')", con);
//ds = new DataSet();
//da.Fill(ds, "Cust");
//MessageBox.Show("Done");
}
private void button2_Click(object sender, EventArgs e)
{
DataRow dr = ds.Tables["Cust"].NewRow();
dr = ds.Tables[0].Rows.Find(textBox1.Text);
dr.Delete();
cbd = new SqlCommandBuilder(da);
da.Update(ds, "Cust");
//da = new SqlDataAdapter("delete from Cust where Cust_ID=" + textBox1.Text, con);
//ds = new DataSet();
//da.Fill(ds, "Cust");
//MessageBox.Show("Deleted");
}
private void button3_Click(object sender, EventArgs e)
{
DataRow drow = ds.Tables[0].NewRow();
drow = ds.Tables[0].Rows.Find(textBox1.Text);
drow[1] = textBox2.Text;
cbd = new SqlCommandBuilder(da);
da.Update(ds, "Cust");
//da = new SqlDataAdapter("update Cust set Cust_Name='" + textBox2.Text + "' where Cust_ID=" + textBox1.Text, con);
//ds = new DataSet();
//da.Fill(ds, "Cust");
//MessageBox.Show("Updated");
}
private void Form1_Load(object sender, EventArgs e)
{
da = new SqlDataAdapter("Select * from Cust", con);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(ds, "Cust");
dataGridView1.DataSource = ds.Tables[0];
}
}
}
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 WindowsFormsApplication3
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection("Data Source=ARNAV;Initial Catalog=Mrudu;User ID=sa;Password=manager");
SqlDataAdapter da;
DataSet ds=new DataSet();
SqlCommandBuilder cbd;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DataRow drow = ds.Tables[0].NewRow();
drow[0] = textBox1.Text;
drow[1] = textBox2.Text;
ds.Tables[0].Rows.Add(drow);
cbd = new SqlCommandBuilder(da);
da.Update(ds, "Cust");
//da = new SqlDataAdapter("insert into Cust values("+textBox1.Text+",'"+textBox2.Text+"')", con);
//ds = new DataSet();
//da.Fill(ds, "Cust");
//MessageBox.Show("Done");
}
private void button2_Click(object sender, EventArgs e)
{
DataRow dr = ds.Tables["Cust"].NewRow();
dr = ds.Tables[0].Rows.Find(textBox1.Text);
dr.Delete();
cbd = new SqlCommandBuilder(da);
da.Update(ds, "Cust");
//da = new SqlDataAdapter("delete from Cust where Cust_ID=" + textBox1.Text, con);
//ds = new DataSet();
//da.Fill(ds, "Cust");
//MessageBox.Show("Deleted");
}
private void button3_Click(object sender, EventArgs e)
{
DataRow drow = ds.Tables[0].NewRow();
drow = ds.Tables[0].Rows.Find(textBox1.Text);
drow[1] = textBox2.Text;
cbd = new SqlCommandBuilder(da);
da.Update(ds, "Cust");
//da = new SqlDataAdapter("update Cust set Cust_Name='" + textBox2.Text + "' where Cust_ID=" + textBox1.Text, con);
//ds = new DataSet();
//da.Fill(ds, "Cust");
//MessageBox.Show("Updated");
}
private void Form1_Load(object sender, EventArgs e)
{
da = new SqlDataAdapter("Select * from Cust", con);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(ds, "Cust");
dataGridView1.DataSource = ds.Tables[0];
}
}
}