Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting a numeric variable from VB to a SQL table

Status
Not open for further replies.

herci

Programmer
Nov 8, 2002
23
PA
hi..

I am trying to insert a numeric value from visual basic but
i don't know the right way to write the format of the comand text. I can insert a string variable like such:

dim cadena as string
cmdinsrt.comandtext = "Insert publisher" & _
"values ('" & cadena & "')

cmdinsrt.execute

How can I insert a numeric value?

any kind of information will be appreciated
 

insert into tablename(fieldname1,fieldname2,etc) values(value1,value2,etc)
 
sorry..
I want to insert a Visual Basic numeric variable to a sql table..

Thanks again!
 
Hi,

In SQL, strings are defined with single quotes ('). In vb it's double quotes("). Simply leave out the single quotes in your SQL statement to insert a numerical value. However, in order to create the VB string that makes up the SQL statement, you'll have to convert the numeric value to a VB string. Get the logic? It looks like this:

MyConnection.Execute "INSERT INTO tblMyTable(MyNumericField) VALUES (" & cstr(MyVBNumericValue) & ")"


Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top