943,865 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 7307
  • VB.NET RSS
Oct 12th, 2008
0

Update Command in Vb.net

Expand Post »
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
vbnet Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 6
Solved Threads: 0
Newbie Poster
mugun is offline Offline
10 posts
since Sep 2008
Oct 12th, 2008
0

Re: Update Command in Vb.net

Enclose text field values in quotes:
VB.NET Syntax (Toggle Plain Text)
  1. Dim strSQL As String = ("UPDATE Staff SET StaffName = ['" & _
  2. namebox.Text & "'] ,Address = ['" & addbox.Text & _
  3. "'] ,Phone = ['" & phone & "'] ,JobPosition = ['" & _
  4. posbox.Text & "'] ,JobStat = ['" & genId & _
  5. "'] WHERE SID='" & id.Text & "'")
If SID field is numeric, remove quotes from it.
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Teme64 is offline Offline
1,024 posts
since Aug 2008
Oct 13th, 2008
0

Re: Update Command in Vb.net

You need to change a command to cmd.ExecuteNonQuery
Reputation Points: 10
Solved Threads: 0
Newbie Poster
siphephelo is offline Offline
1 posts
since Feb 2006
Mar 5th, 2010
0
Re: Update Command in Vb.net
I would build a dataAdapter for this instead.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JdTSC is offline Offline
5 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Double your pay application
Next Thread in VB.NET Forum Timeline: Best way for creating quiz





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC