how to save data from textbox to msaccess 2003

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

Join Date: Jan 2009
Posts: 7
Reputation: vb.babyboy is an unknown quantity at this point 
Solved Threads: 0
vb.babyboy vb.babyboy is offline Offline
Newbie Poster

how to save data from textbox to msaccess 2003

 
0
  #1
Jan 20th, 2009
hi everyone,

im very new to vb.net.

i have a textbox and a save button on my form.

i have already connected the database to my application...

pls can any1 tell m how do i save the data in the textbox to my ms access databse when i click on btnsave...

can sum1 pls guide m by giving me the code
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: how to save data from textbox to msaccess 2003

 
0
  #2
Jan 21st, 2009
Here's a sample
  1. Dim oCon As OdbcConnection
  2. Dim oCmd As OdbcCommand
  3. Dim ConnStr As String
  4. Dim strSQL As String
  5.  
  6. ConnStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=<path to mdb file>"
  7. oCon = New OdbcConnection(ConnStr)
  8. oCon.Open()
  9. oCmd = oCon.CreateCommand()
  10. strSQL = "INSERT INTO <tablename> (<fieldname>) VALUES ('" & TextBox1.Text.Replace("'", "''") & "')"
  11. oCmd.CommandText = strSQL
  12. oCmd.ExecuteNonQuery()
  13. oCon.Close()
Replace correct strings to connection string, table name and field name, and add some error handling code.

If you have trouble with connection string see Connection strings for Access.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 7
Reputation: vb.babyboy is an unknown quantity at this point 
Solved Threads: 0
vb.babyboy vb.babyboy is offline Offline
Newbie Poster

Re: how to save data from textbox to msaccess 2003

 
0
  #3
Jan 21st, 2009
hi, thx vey much for the help... as i tld you im very new to vb.net 05...

i have pasted the code in my click method...

well i knw that i have to edit it frst

i have attached a preview of how my code is...

but why is "OdbcConnection" highlighted saying it is not declared. pls check the coding and guide me pls....
Attached Thumbnails
test.jpg  
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: how to save data from textbox to msaccess 2003

 
1
  #4
Jan 22nd, 2009
write this on the top of codes
  1. Imports System.Data.Odbc
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 7
Reputation: vb.babyboy is an unknown quantity at this point 
Solved Threads: 0
vb.babyboy vb.babyboy is offline Offline
Newbie Poster

Re: how to save data from textbox to msaccess 2003

 
0
  #5
Jan 22nd, 2009
hi,

im still having trouble to save data to access..

i have attached my code in JPG format...

My little app is supposed to save data from a textbox to a field in access...

i dont get any errors while running the application.. but it just wont save the data.. cantr understand why...

Pls help... i really need to understand this..

Thank You...
Attached Thumbnails
Code.jpg  
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 7
Reputation: vb.babyboy is an unknown quantity at this point 
Solved Threads: 0
vb.babyboy vb.babyboy is offline Offline
Newbie Poster

Re: how to save data from textbox to msaccess 2003

 
0
  #6
Jan 23rd, 2009
Hi, i managed to make it work.. now my another prob is, how do i amend the code is i had 2 textbox and to save the data into ms access...

i tried this but its not working:

mycommand.CommandText = "INSERT INTO TBLSuppliers (Company, Contact Person) VALUES ('" & txtCompany.Text.Replace , & txtContactPerson.text.replace ("'", "''") & "')"
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



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