Professional Documents
Culture Documents
D. ROOPA SREE
LAB-6
A)
1. using System;
2. using System.Collections.Generic;
3. using System.ComponentModel;
4. using System.Data;
5. using System.Drawing;
6. using System.Linq;
7. using System.Text;
8. using System.Threading.Tasks;
9. using System.Windows.Forms;
10. using System.Data.SqlClient;
11.
12. namespace WindowsFormsDataGrid {
13.
14. public partial class Form1: Form {
15.
16. public Form1() {
17. InitializeComponent();
18. }
19.
20. private void Form1_Load(object sender, EventArgs e) {
21. SqlDataAdapter da = new SqlDataAdapter("SELECT * FR
OM Student", "server = MCNDESKTOP33; database = Avinash; UID = s
a; password = *******");
22. DataSet ds = new DataSet();
23. da.Fill(ds, "Student");
24. dataGridView1.DataSource = ds.Tables["Student"].Def
aultView;
25. }
26.
27. private void button1_Click(object sender, EventArgs e)
{
28. SqlConnection con = new SqlConnection("server = MCN
DESKTOP33; database = Avinash; UID = sa; password = *******");
29. con.Open();
30. string qur = "INSERT INTO Student VALUES ('" + text
Box1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','
" + textBox4.Text + "')";
31.
32. SqlCommand cmd = new SqlCommand(qur, con);
33. cmd.ExecuteNonQuery();
34. con.Close();
35. MessageBox.Show("Inserted sucessfully");
36. textBox1.Text = "";
37. textBox2.Text = "";
38. textBox3.Text = "";
39. textBox4.Text = "";
40. }
41.
42. private void button2_Click(object sender, EventArgs e)
{
43. textBox1.Text = "";
44. textBox2.Text = "";
45. textBox3.Text = "";
46. textBox4.Text = "";
47.
48. }
49. }
50. }