help in my linkin....

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

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

help in my linkin....

 
0
  #1
Oct 4th, 2008
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
  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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 121
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: help in my linkin....

 
0
  #2
Oct 4th, 2008
do you get error, or the program run but no change made to database or what ?
"give only what u willing to receive "
Reply With Quote Quick reply to this message  
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

Re: help in my linkin....

 
0
  #3
Oct 5th, 2008
i get an error,syntax error in INSERT INTO STATEMENT....i get tht manal....any idea?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC