View Single Post
Join Date: Sep 2008
Posts: 10
Reputation: mugun has a little shameless behaviour in the past 
Solved Threads: 0
mugun mugun is offline Offline
Newbie Poster

Update Command in Vb.net

 
0
  #1
Oct 12th, 2008
i am writing a code where the user will update the staff,but my update command has some problems. i think its the comma's in my command,can somebody help me.......

this is my code
  1. Imports System.Data.OleDb
  2. Public Class EditDeleteStaff
  3.  
  4. Dim PwdCon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "/Blindz.mdb; Jet OLEDB:Database Password=;" 'Persist Security Info=False;" if your DB is not PWD protected
  5. Dim oledbcon As New OleDbConnection(PwdCon)
  6. Dim dsID As New DataSet()
  7. Dim daID As New OleDbDataAdapter()
  8. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  9. Me.Hide()
  10. Manager.Show()
  11. End Sub
  12.  
  13. Private Sub EditDeleteStaff_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  14. Dim PwdCon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "/Blindz.mdb; Jet OLEDB:Database Password=;"
  15. Dim oledbcon As New OleDbConnection(PwdCon)
  16. End Sub
  17. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  18. Dim jobstat As String = ""
  19. Dim num1, num2, num3, num4, num5, num6 As Boolean
  20. Dim phone, icnum, genId As String
  21. Dim i As Integer = 0
  22. num1 = IsNumeric(telbox.Text)
  23. num2 = IsNumeric(telbox2.Text)
  24. num3 = IsNumeric(IcNumbox.Text)
  25. num4 = IsNumeric(IcNumbox2.Text)
  26. num5 = IsNumeric(IcNumbox3.Text)
  27. num6 = IsChar(namebox.Text)
  28. If Ftime.Checked = True Then
  29. jobstat = Ftime.Text
  30. End If
  31. If Ptime.Checked = True Then
  32. jobstat = Ptime.Text
  33. End If
  34.  
  35. 'THIS ALL CHANGE TO UPDATEEEE!!!!!
  36.  
  37.  
  38. If namebox.Text = "" OrElse _
  39. addbox.Text = "" OrElse _
  40. telbox2.Text = "" OrElse _
  41. telbox.Text = "" OrElse _
  42. syspass.Text = "" OrElse _
  43. IcNumbox.Text = "" OrElse _
  44. IcNumbox2.Text = "" OrElse _
  45. IcNumbox3.Text = "" OrElse _
  46. posbox.Text = "" OrElse _
  47. jobstat = "" Then
  48. MessageBox.Show("All feilds must be filled")
  49.  
  50. ElseIf num1 = False Or num2 = False Or num3 = False Or num4 = False Or num5 = False Then
  51. MessageBox.Show("Ic number and telephone number cannot have characters")
  52. ElseIf num6 = False Then
  53. MessageBox.Show("Name Cannot Contain Numbers")
  54. ElseIf telbox.TextLength < 2 Or telbox2.TextLength < 7 Then
  55. MessageBox.Show("Not a Valid telephone Number")
  56. ElseIf IcNumbox.TextLength < 6 Or IcNumbox2.TextLength < 2 Or IcNumbox3.TextLength < 4 Then
  57. MessageBox.Show("Not a Valid Malaysian Ic Number")
  58. Else
  59. phone = telbox.Text + "-" + telbox2.Text
  60. icnum = IcNumbox.Text + "-" + IcNumbox2.Text + "-" + IcNumbox3.Text
  61. Try
  62. oledbcon.Open()
  63. Dim strSQL As String = ("UPDATE Staff SET StaffName = [" & namebox.Text & "] ,Address = [" & addbox.Text & "] ,Phone = [" & phone & "] ,JobPosition = [" & posbox.Text & "] ,JobStat = [" & genId & "] WHERE {SID=" & id.Text & "}")
  64. Dim cmd As OleDbCommand = New OleDbCommand(strSQL, oledbcon)
  65. Dim objread As OleDbDataReader
  66. objread = cmd.ExecuteReader
  67.  
  68. Catch ex As Exception
  69. MessageBox.Show(ex.Message)
  70. Finally
  71. oledbcon.Close()
  72. End Try
  73. End If
  74. End Sub
Last edited by cscgal; Oct 12th, 2008 at 4:34 pm. Reason: Added code tags
Reply With Quote