註冊.vb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. Imports System.Data.SqlClient
  2. Public Class 註冊
  3. Dim conn As New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\奕穎\Documents\資管\大三上\系分\謎鹿\謎鹿.mdf;Integrated Security=True;Connect Timeout=30")
  4. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  5. conn.Open()
  6. Dim i As Integer = 會員DataGridView.CurrentRow.Index
  7. Dim m_會員編號 = TextBox1.Text
  8. Dim m_帳號 = TextBox1.Text
  9. Dim m_密碼 = TextBox2.Text
  10. Dim m_姓名 = TextBox4.Text
  11. Dim m_email = TextBox5.Text
  12. Dim m_電話 = TextBox6.Text
  13. Dim m_住址 = TextBox7.Text
  14. If (TextBox2.Text <> TextBox3.Text) Then
  15. MsgBox("密碼必須一致!!")
  16. End If
  17. Dim sqladd As String = "INSERT INTO 會員(會員編號,帳號,密碼,姓名,電話,住址,email) VALUES('" & TextBox1.Text & "','" & TextBox1.Text & "','" & TextBox2.Text & "',N'" & TextBox4.Text & "','" & TextBox6.Text & "',N'" & TextBox7.Text & "','" & TextBox5.Text & "')"
  18. Dim add = New SqlCommand(sqladd, conn)
  19. add.ExecuteNonQuery()
  20. MsgBox("註冊成功!!!")
  21. conn.Close()
  22. Try
  23. Me.會員TableAdapter.InsertQuery(m_會員編號, m_帳號, m_密碼, m_姓名, m_電話, m_住址, m_email)
  24. Catch ex As Exception
  25. End Try
  26. Me.會員DataGridView.Refresh()
  27. Me.會員BindingSource.DataSource = 會員TableAdapter.GetData()
  28. Me.會員BindingSource.ResetBindings(False)
  29. End Sub
  30. Private Sub 註冊_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  31. 'TODO: 這行程式碼會將資料載入 '謎鹿DataSet.會員' 資料表。您可以視需要進行移動或移除。
  32. Me.會員TableAdapter.Fill(Me.謎鹿DataSet.會員)
  33. End Sub
  34. End Class