Need Help to insert data to MS Access table

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2009
Posts: 41
Reputation: VIPER5646 is an unknown quantity at this point 
Solved Threads: 0
VIPER5646's Avatar
VIPER5646 VIPER5646 is offline Offline
Light Poster

Need Help to insert data to MS Access table

 
0
  #1
Mar 6th, 2009
I been searching for days for a sulotion but can't seem to find one.
The coed that I have does not give me an error but it does not save anything on the table either '
Can someone help me find what I'm missing?
this is my coed

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim mycon As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\DEsign.accdb"
  2. Dim customer As String = "select * from Customer_tbl"
  3. Dim Notes As String = "select * from Notes_tbl"
  4. Dim con As New OleDb.OleDbConnection(mycon)
  5. Dim comCustomer As New OleDb.OleDbCommand(customer, con)
  6. Dim comdNotes As New OleDb.OleDbCommand(Notes, con)
  7. Dim Custsql As String = "first name,Last Name"
  8. Dim Sql As String = "insert into Customer_tbl (Custsql )values '" & txtFirstName.Text & "','" & txtLastName.Text & "')"
  9. comCustomer = New OleDb.OleDbCommand(Sql, con)
  10.  
  11. con.Open()
  12. comCustomer.ExecuteNonQuery()
  13. comCustomer.Dispose()
  14. con.Close()
Thank you
Viper
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,107
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 128
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: Need Help to insert data to MS Access table

 
0
  #2
Mar 9th, 2009
i don't think that is VB 6.0 code.

if vb 6.0 then try this
  1. Dim Sql As String = "insert into Customer_tbl (Custsql )values '" & txtFirstName.Text & "','" & txtLastName.Text & "')"
  2. con.begintrans 'con-----ADODB connection object.
  3. con.execute sql
  4. con.committrans
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 41
Reputation: VIPER5646 is an unknown quantity at this point 
Solved Threads: 0
VIPER5646's Avatar
VIPER5646 VIPER5646 is offline Offline
Light Poster

Re: Need Help to insert data to MS Access table

 
0
  #3
Mar 9th, 2009
Originally Posted by debasisdas View Post
i don't think that is VB 6.0 code.

if vb 6.0 then try this
  1. Dim Sql As String = "insert into Customer_tbl (Custsql )values '" & txtFirstName.Text & "','" & txtLastName.Text & "')"
  2. con.begintrans 'con-----ADODB connection object.
  3. con.execute sql
  4. con.committrans
thanks for your reply.
when I try the coed I get an error that execute and committrans are not members of the OLEDB.
I'm using Acess 2007 as a Database. Hope this helps.
Thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,107
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 128
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: Need Help to insert data to MS Access table

 
0
  #4
Mar 10th, 2009
Are you using ADO to connect to the database ?
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 41
Reputation: VIPER5646 is an unknown quantity at this point 
Solved Threads: 0
VIPER5646's Avatar
VIPER5646 VIPER5646 is offline Offline
Light Poster

Re: Need Help to insert data to MS Access table

 
0
  #5
Mar 10th, 2009
Originally Posted by debasisdas View Post
Are you using ADO to connect to the database ?
No i'm using OLEDB
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 841
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 153
vb5prgrmr vb5prgrmr is offline Offline
Practically a Posting Shark

Re: Need Help to insert data to MS Access table

 
0
  #6
Mar 10th, 2009
Originally Posted by VIPER5646 View Post
I been searching for days for a sulotion but can't seem to find one.
The coed that I have does not give me an error but it does not save anything on the table either '
Can someone help me find what I'm missing?
this is my coed

 Dim mycon As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\DEsign.accdb"
        Dim customer As String = "select * from Customer_tbl"
        Dim Notes As String = "select * from Notes_tbl"
        Dim con As New OleDb.OleDbConnection(mycon)
        Dim comCustomer As New OleDb.OleDbCommand(customer, con)
        Dim comdNotes As New OleDb.OleDbCommand(Notes, con)
        Dim Custsql As String = "first name,Last Name"
        Dim Sql As String = "insert into Customer_tbl (Custsql )values '" & txtFirstName.Text & "','" & txtLastName.Text & "')"
        comCustomer = New OleDb.OleDbCommand(Sql, con)
        
        con.Open()
        comCustomer.ExecuteNonQuery()
       comCustomer.Dispose()
        con.Close()
Thank you
Viper
Should be...

Insert Into Table Values (Field_1_Name, Field_2_Name) Values (Field_1_Value, Field_2_Value)

Good Luck
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,107
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 128
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: Need Help to insert data to MS Access table

 
0
  #7
Mar 11th, 2009
what is that CON in your code ?

What type of object is that ?
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 41
Reputation: VIPER5646 is an unknown quantity at this point 
Solved Threads: 0
VIPER5646's Avatar
VIPER5646 VIPER5646 is offline Offline
Light Poster

Re: Need Help to insert data to MS Access table

 
0
  #8
Mar 12th, 2009
HI v5prgrmr
I tried your QRY and now I get an error.
The error is ( Missing Semicolon at the end oof the SQL statement.
I have tried to place a Semicolon at the end and in diferent places in the SQL but I continue to get the same error.
This is my updated SQL statement.
Dim mysql As String = "insert into Customer_tbl values('First Name','Last Name') values ('John','Unknown');"
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 41
Reputation: VIPER5646 is an unknown quantity at this point 
Solved Threads: 0
VIPER5646's Avatar
VIPER5646 VIPER5646 is offline Offline
Light Poster

Re: Need Help to insert data to MS Access table

 
0
  #9
Mar 12th, 2009
[QUOTE] Hi Debasisdas
TEX]If I understood your question my Con is posted.
If you see my coed that is my CON.[/TEX]
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 841
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 153
vb5prgrmr vb5prgrmr is offline Offline
Practically a Posting Shark

Re: Need Help to insert data to MS Access table

 
0
  #10
Mar 13th, 2009
Originally Posted by VIPER5646 View Post
HI v5prgrmr

Dim mysql As String = "insert into Customer_tbl values('First Name','Last Name') values ('John','Unknown');"
Ahh... My bust.

Dim mysql As String = "insert into Customer_tbl ('First Name','Last Name') values ('John','Unknown');"
Remove that first values
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC