private void button1_Click(object sender, EventArgs e) { try { cn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO Sample(Value) VALUES (@NAME)", cn); cmd.Parameters.AddWithValue("Name",textBox1.Text); cmd.ExecuteNonQuery(); MessageBox.Show("Success"); cn.Close(); } catch { MessageBox.Show("Error"); } } private void button2_Click(object sender, EventArgs e) { try { cn.Open(); da = new SqlDataAdapter("Select * from Sample", cn); ds = new DataSet(); da.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; cn.Close(); } catch { MessageBox.Show("Error"); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)