Welcome to dbFreaks.com!
FAQFAQ   SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log in/Register/PasswordLog in/Register/Password

INSERT SQL query help with VB please?

 
   Database Help (Home) -> Visual Basic RSS
Related Topics:
NEWBIE insert data rather than update in db - I have an app for tracking mileage on company vehicles. On the first form you select a combobox getting vehicle names from database) and enter the info. Then I need to export that data back to the database. The ? is how do I..

update query - I have created an update query in my to change the date in the bound table to the sys date. However, the query will not accept '=Date' in the new value box. Does anyone know the correct function. The help gives it as 'Date' Ian

sql query returns in wrong format - Hi, Hope someone can help me with this. I have MS SQL 2000 database where i have Table and there a column wich is data type All data in this column is in form So why when i run .asp page with simple query to..

arrays - is there a way to the contents of an array (looping through the array) and storing each item in a comma delimited string? Thanks!

DataReport PageBreak - Hi everyone, I would like to know how to force pagebreak in a for example after 5 records printed. Thank you all
Next:  Visual Basic: Creating reports in VB6  
Author Message
Ant

External


Since: Feb 16, 2005
Posts: 10



(Msg. 1) Posted: Wed Feb 16, 2005 4:41 pm
Post subject: INSERT SQL query help with VB please?
Archived from groups: comp>lang>basic>visual>database (more info?)

Hello,

I am trying to run an SQL query on a database through VB6 which is supposed
to add data to a table called tblNames. There are 4 text fields on the form
where data is added.

here's the code.

Dim i As Integer
Set db1 = New ADODB.Connection
db1.Provider = "Microsoft.Jet.OLEDB.4.0;"
db1.ConnectionString = "c:\database.mdb"
db1.Open
Set rs = New ADODB.Recordset
rs.Open "INSERT INTO tblNames VALUES(" + txtID.Text + "," + txtNameF.Text +
"," + txtNameL.Text + "," + txtAddress.Text + ")", db1

I get run time error 424 Object Required - and I don't understand what this
means?

The primary field (ID) is an autonumber, do you think that could be causing
problems?

If anyone could help that would be brilliant!

 >> Stay informed about: INSERT SQL query help with VB please? 
Back to top
Login to vote
Michael B. Johnson

External


Since: May 14, 2004
Posts: 16



(Msg. 2) Posted: Wed Feb 16, 2005 4:41 pm
Post subject: Re: INSERT SQL query help with VB please? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

To: "Ant" <nospamf.DeleteThis@nospam.com>
Subject: Re: INSERT SQL query help with VB please?
From: Michael B. Johnson <mjohnson.DeleteThis@veribox.net>
Date: Wed, 16 Feb 2005 14:46:14 -0600

On Wed, 16 Feb 2005 19:31:49 -0000, in comp.lang.basic.visual.database
you wrote:

 >I am trying to run an SQL query on a database through VB6 which is supposed
 >to add data to a table called tblNames. There are 4 text fields on the form
 >where data is added.
 >
 >here's the code.
 >
 >Dim i As Integer
 >Set db1 = New ADODB.Connection
 >db1.Provider = "Microsoft.Jet.OLEDB.4.0;"
 >db1.ConnectionString = "c:\database.mdb"
 >db1.Open
 >Set rs = New ADODB.Recordset
 >rs.Open "INSERT INTO tblNames VALUES(" + txtID.Text + "," + txtNameF.Text +
 >"," + txtNameL.Text + "," + txtAddress.Text + ")", db1
 >
 >I get run time error 424 Object Required - and I don't understand what this
 >means?

You need to add single quotes around the text values like this:

sSQL = "INSERT INTO tblNames VALUES('" & txtID.Text & "','" &
txtNameF.Text & "','" & txtNameL.Text & "','" & txtAddress.Text & "')"

db1.Execute sSQL ' don't use rs.Open for a query that won't return any
    'records.


_______________________
Michael B. Johnson<!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: INSERT SQL query help with VB please? 
Back to top
Login to vote
Veign

External


Since: Apr 22, 2004
Posts: 13



(Msg. 3) Posted: Wed Feb 16, 2005 5:40 pm
Post subject: Re: INSERT SQL query help with VB please? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Adding:

Check out the SQL Reference Guide at:
<a style='text-decoration: underline;' href="http://www.veign.com/vrc_app_main.asp" target="_blank">http://www.veign.com/vrc_app_main.asp</a>

This will provide a handy reference on common SQL statements...

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
<a style='text-decoration: underline;' href="http://www.veign.com/vrc_main.asp" target="_blank">http://www.veign.com/vrc_main.asp</a>
--

"Ant" <nospamf RemoveThis @nospam.com> wrote in message
news:cv0737$q6l$1@wisteria.csv.warwick.ac.uk...
 > Hello,
 >
 > I am trying to run an SQL query on a database through VB6 which is
supposed
 > to add data to a table called tblNames. There are 4 text fields on the
form
 > where data is added.
 >
 > here's the code.
 >
 > Dim i As Integer
 > Set db1 = New ADODB.Connection
 > db1.Provider = "Microsoft.Jet.OLEDB.4.0;"
 > db1.ConnectionString = "c:\database.mdb"
 > db1.Open
 > Set rs = New ADODB.Recordset
 > rs.Open "INSERT INTO tblNames VALUES(" + txtID.Text + "," + txtNameF.Text
+
 > "," + txtNameL.Text + "," + txtAddress.Text + ")", db1
 >
 > I get run time error 424 Object Required - and I don't understand what
this
 > means?
 >
 > The primary field (ID) is an autonumber, do you think that could be
causing
 > problems?
 >
 > If anyone could help that would be brilliant!
 >
 ><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: INSERT SQL query help with VB please? 
Back to top
Login to vote
Ant

External


Since: Feb 16, 2005
Posts: 10



(Msg. 4) Posted: Wed Feb 16, 2005 8:40 pm
Post subject: Re: INSERT SQL query help with VB please? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Michael B. Johnson" <mjohnson.TakeThisOut@veribox.net> wrote in message
news:b9c7111u0bacs7u3j31felrp4j9saibogs@4ax.com...
 > To: "Ant" <nospamf.TakeThisOut@nospam.com>
 > Subject: Re: INSERT SQL query help with VB please?
 > From: Michael B. Johnson <mjohnson.TakeThisOut@veribox.net>
 > Date: Wed, 16 Feb 2005 14:46:14 -0600
 >
 > On Wed, 16 Feb 2005 19:31:49 -0000, in comp.lang.basic.visual.database
 > you wrote:
 >
  >>I am trying to run an SQL query on a database through VB6 which is
  >>supposed
  >>to add data to a table called tblNames. There are 4 text fields on the
  >>form
  >>where data is added.
  >>
  >>here's the code.
  >>
  >>Dim i As Integer
  >>Set db1 = New ADODB.Connection
  >>db1.Provider = "Microsoft.Jet.OLEDB.4.0;"
  >>db1.ConnectionString = "c:\database.mdb"
  >>db1.Open
  >>Set rs = New ADODB.Recordset
  >>rs.Open "INSERT INTO tblNames VALUES(" + txtID.Text + "," + txtNameF.Text
  >>+
  >>"," + txtNameL.Text + "," + txtAddress.Text + ")", db1
  >>
  >>I get run time error 424 Object Required - and I don't understand what
  >>this
  >>means?
 >
 > You need to add single quotes around the text values like this:
 >
 > sSQL = "INSERT INTO tblNames VALUES('" & txtID.Text & "','" &
 > txtNameF.Text & "','" & txtNameL.Text & "','" & txtAddress.Text & "')"
 >
 > db1.Execute sSQL ' don't use rs.Open for a query that won't return any
 > 'records.
 >
 >
 > _______________________
 > Michael B. Johnson

cheers for that, its sorted me out!<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: INSERT SQL query help with VB please? 
Back to top
Login to vote
Ant

External


Since: Feb 16, 2005
Posts: 10



(Msg. 5) Posted: Wed Feb 16, 2005 8:40 pm
Post subject: Re: INSERT SQL query help with VB please? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Veign" <me RemoveThis @home.com> wrote in message
news:dYOQd.2683$9J5.1845@newsread2.news.atl.earthlink.net...
 > Adding:
 >
 > Check out the SQL Reference Guide at:
<font color=purple> > <a style='text-decoration: underline;' href="http://www.veign.com/vrc_app_main.asp</font" target="_blank">http://www.veign.com/vrc_app_main.asp</font</a>>
 >
 > This will provide a handy reference on common SQL statements...
 >
 > --
 > Chris Hanscom - Microsoft MVP (VB)
 > Veign's Resource Center
<font color=purple> > <a style='text-decoration: underline;' href="http://www.veign.com/vrc_main.asp</font" target="_blank">http://www.veign.com/vrc_main.asp</font</a>>
 > --

that's very useful, thanks!<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: INSERT SQL query help with VB please? 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> Visual Basic All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]