943,981 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 2699
  • VB.NET RSS
Jan 20th, 2009
1

how to save data from textbox to msaccess 2003

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vb.babyboy is offline Offline
7 posts
since Jan 2009
Jan 21st, 2009
0

Re: how to save data from textbox to msaccess 2003

Here's a sample
VB.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Teme64 is offline Offline
1,024 posts
since Aug 2008
Jan 21st, 2009
0

Re: how to save data from textbox to msaccess 2003

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
Click image for larger version

Name:	test.jpg
Views:	116
Size:	60.5 KB
ID:	8920  
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vb.babyboy is offline Offline
7 posts
since Jan 2009
Jan 22nd, 2009
3

Re: how to save data from textbox to msaccess 2003

write this on the top of codes
VB.NET Syntax (Toggle Plain Text)
  1. Imports System.Data.Odbc
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,144 posts
since Nov 2007
Jan 22nd, 2009
0

Re: how to save data from textbox to msaccess 2003

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
Click image for larger version

Name:	Code.jpg
Views:	95
Size:	94.8 KB
ID:	8943  
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vb.babyboy is offline Offline
7 posts
since Jan 2009
Jan 23rd, 2009
0

Re: how to save data from textbox to msaccess 2003

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 ("'", "''") & "')"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vb.babyboy is offline Offline
7 posts
since Jan 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: DataGrid reads, but not updates!
Next Thread in VB.NET Forum Timeline: vb.net and compact framework?





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


Follow us on Twitter


© 2011 DaniWeb® LLC