943,741 Members | Top Members by Rank

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

help in my linkin....

Expand Post »
i have written a vb.net coding for linkin my vb interface to my access database...its all the same....but some linking codes i wrote work,for other forms,but sum don work...
this is 1...its a form to add staff in my system
vb Syntax (Toggle Plain Text)
  1. Imports System.Data
  2. Imports System.Data.OleDb
  3. Public Class Form1
  4. Dim ds As New DataSet
  5. Dim data As New OleDbDataAdapter
  6. Dim conn As New OleDbConnection
  7. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  8. conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Group Project\Staff\Staff\bin\Debug\Blindz.mdb;User Id=;Password=;"
  9.  
  10. data.SelectCommand = New OleDbCommand("SELECT * FROM Staff")
  11. data.SelectCommand.Connection = conn
  12. data.Fill(ds)
  13.  
  14. data.InsertCommand = New OleDbCommand("INSERT INTO Staff(StaffName,BirthDate,Gender,Address,Phone,Position,StaffID,SystemPassword) VALUES(@StaffName,@BirthDate,@Gender,@Address,@Phone,@Position,@StaffID,@SystemPassword)")
  15. data.InsertCommand.Connection = conn
  16. data.InsertCommand.Parameters.Add("@StaffName", OleDbType.VarChar, 40, "StaffName")
  17. data.InsertCommand.Parameters.Add("@BirthDate", OleDbType.VarChar, 40, "BirthDate")
  18. data.InsertCommand.Parameters.Add("@Gender", OleDbType.VarChar, 40, "Gender")
  19. data.InsertCommand.Parameters.Add("@Address", OleDbType.VarChar, 40, "Address")
  20. data.InsertCommand.Parameters.Add("@Phone", OleDbType.VarChar, 40, "Phone")
  21. data.InsertCommand.Parameters.Add("@Pos", OleDbType.VarChar, 40, "Pos")
  22. data.InsertCommand.Parameters.Add("@StaffID", OleDbType.VarChar, 40, "StaffID")
  23. data.InsertCommand.Parameters.Add("@SysPassword", OleDbType.VarChar, 40, "SysPassword")
  24. End Sub
  25.  
  26. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  27. Dim dr As DataRow
  28.  
  29. dr = ds.Tables(0).NewRow() 'Gets a reference to a new row.
  30. dr("StaffName") = namebox.Text
  31. dr("BirthDate") = datebox.Value
  32. dr("Gender") = genbox.Text
  33. dr("Address") = addbox.Text
  34. dr("Phone") = phonebox.Text
  35. dr("Pos") = posbox.Text
  36. dr("StaffID") = id.Text
  37. dr("SysPassword") = syspass.Text
  38.  
  39. ds.Tables(0).Rows.Add(dr)
  40. data.Update(ds)
  41. ds.AcceptChanges()
  42. End Sub
  43. End Class

Thats my code above, my access fields are all text....coz i always get errors if i use other types.....can sum1 plz help me....i also noticed there are numerous ways to use ole.db to add to database....can sum1 tel me waths wrong??.....thank you....
Last edited by Tekmaven; Oct 4th, 2008 at 7:06 pm. Reason: Code tags
Similar Threads
Reputation Points: 6
Solved Threads: 0
Newbie Poster
mugun is offline Offline
10 posts
since Sep 2008
Oct 4th, 2008
0

Re: help in my linkin....

do you get error, or the program run but no change made to database or what ?
Reputation Points: 37
Solved Threads: 17
Junior Poster
manal is offline Offline
122 posts
since Mar 2006
Oct 5th, 2008
0

Re: help in my linkin....

i get an error,syntax error in INSERT INTO STATEMENT....i get tht manal....any idea?
Reputation Points: 6
Solved Threads: 0
Newbie Poster
mugun is offline Offline
10 posts
since Sep 2008

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: Date and oledb
Next Thread in VB.NET Forum Timeline: using generic procedures





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


Follow us on Twitter


© 2011 DaniWeb® LLC