Advertisement
rofelbca

vb.net

Mar 13th, 2024 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. Imports System.Data.SqlClient
  2. Imports System.Data
  3. Public Class Form1
  4.  
  5. Dim con As New SqlConnection("Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=databse2;Integrated Security=True")
  6. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  7. Dim cmd As New SqlCommand("insert into customer values(@cid , @cname , @dob,@gender,@city)", con)
  8. cmd.Parameters.AddWithValue("@cid", TextBox1.Text)
  9. cmd.Parameters.AddWithValue("@cname", TextBox2.Text)
  10. cmd.Parameters.AddWithValue("@dob", TextBox3.Text)
  11. cmd.Parameters.AddWithValue("@gender", TextBox3.Text)
  12. cmd.Parameters.AddWithValue("@city", TextBox3.Text)
  13. cmd.ExecuteNonQuery()
  14. MsgBox("your data Submit successfully")
  15.  
  16. End Sub
  17. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  18. 'TODO: This line of code loads data into the 'Database23DataSet.customer' table. You can move, or remove it, as needed.
  19. Me.CustomerTableAdapter1.Fill(Me.Database23DataSet.customer)
  20. con.Open()
  21. End Sub
  22. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  23. Dim adpt As New SqlDataAdapter("select * from customer", con)
  24. Dim ds As New DataSet()
  25. adpt.Fill(ds, "jadu")
  26. DataGridView1.DataSource = ds
  27. DataGridView1.DataMember = "jadu"
  28. End Sub
  29.  
  30. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  31. Dim cmd As New SqlCommand("update customer set cname = @cname , City = @City where cid = @cid ", con)
  32. cmd.Parameters.AddWithValue("@cid", TextBox1.Text)
  33. cmd.Parameters.AddWithValue("@cname", TextBox2.Text)
  34. cmd.Parameters.AddWithValue("@City", TextBox3.Text)
  35. cmd.ExecuteNonQuery()
  36. MsgBox("your data Updated successfully")
  37. Dim adpt As New SqlDataAdapter("select * from customer", con)
  38. Dim ds As New DataSet()
  39. adpt.Fill(ds, "jadu")
  40. DataGridView1.DataSource = ds
  41. DataGridView1.DataMember = "jadu"
  42. End Sub
  43.  
  44. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  45. Dim cmd As New SqlCommand("delete from customer where cid=@cid", con)
  46. cmd.Parameters.AddWithValue("@cid", TextBox1.Text)
  47. cmd.ExecuteNonQuery()
  48. MsgBox("your data Delete successfully")
  49. Dim adpt As New SqlDataAdapter("select * from customer", con)
  50. Dim ds As New DataSet()
  51. adpt.Fill(ds, "jadu")
  52. DataGridView1.DataSource = ds
  53. DataGridView1.DataMember = "jadu"
  54.  
  55. End Sub
  56. End Class
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement