using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsFormsApplication1 { public partial class Form5 : Form { string connetionString = null; SqlConnection cn; SqlCommandBuilder cb; DataSet s1; SqlDataAdapter da; public Form5() { InitializeComponent(); } private void form5_Load(object Sender, EventArgs e) { string connectionString = null; SqlConnection cn; connectionString = "Data Source=SHAKIR-PC\\SQLEXPRESS;Initial Catalog=UDdata;Integrated Security=True;Pooling=False"; cn = new SqlConnection(connectionString); string sqlQuerry = "select * from UDdata"; da = new SqlDataAdapter(sqlQuerry, cn); s1 = new DataSet(); da.Fill(s1, "UDdata"); } private void button1_Click(object sender, EventArgs e) { try { cb = new SqlCommandBuilder(da); // to insetr the details in form to the datavase tables we need an object DataRow drow = s1.Tables["customer"].NewRow(); drow[0] = textBox1.Text; drow[1] = textBox2.Text; drow[2] = textBox3.Text; s1.Tables["customer"].Rows.Add(drow); da.Update(s1, "customer"); MessageBox.Show("Data Successfully added", "Done"); } catch (Exception ee) { MessageBox.Show("There is an error " + ee.Message); } textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)