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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT sql script

Status
Not open for further replies.

CookieNZ

MIS
Apr 22, 2002
48
NZ
I am tring to use an inser sql to update the database.

insertSQL = "INSERT INTO Supportcall(ID,Contact,Description)" & " VALUES(txtcallnumber.text,txtcallcontact.text,txtcalldescription.text)"

where txtcallnumber.text are cells in the form.

When I run the app, the exception message is No Value Given for one or more parameters.

The access 2k table only has the 3 fields outlined above

If I 'manually' insert the record it works fine.

insertSQL = "INSERT INTO Supportcall(ID,Contact,Description)" & " VALUES('2','Fred Atkins','This is the description')"

Furthermore, I have a declared the fields as
dr = dssupport.Tables("Supportcall").NewRow()
dr("ID") = txtcallnumber.Text
dr("Description") = txtcalldescription.Text
dr("Contact") = txtcallcontact.Text
 
You have to extract the values from your objects... what you've done there is pass in their names -- notice the quotes, indicating a string literal rather than an evaluated statement.

insertSQL = "INSERT INTO Supportcall(ID,Contact,Description)" & " VALUES('" & txtcallnumber.text & "','" & txtcallcontact.text & "','" & txtcalldescription.text & "')"

But check out the FAQ on string concatenation in vb.net. There's a better (read - faster) way to skin this cat.

faq855-1882

:)
paul
penny1.gif
penny1.gif
 
Brilliant, thanks very much.

I have read the FAQ, but since I only need to insert once, I will set the string manually.

sqlscript = "INSERT INTO Supportcall(ID,Description,Date,Status,Operator,Action,Customer,Contact)" & " VALUES('" & txtcallnumber.Text & "','" & txtcalldescription.Text & "','" & txtdate.Text & "','" & txtstatus.Text & "','" & txtoperator.Text & "','" & txtaction.Text & "','" & cmbcustomer.Text & "','" & txtcallcontact.Text & "')"

This still gives me an error when I run the application. Any ideas?
 
Probably have a single tick around a field that isn't supposed to be text. That'd be my guess.

But as for building your string, you really should use the stringbuilder. Doing it that way abuses your memory. But it's your app. ;-)
penny1.gif
penny1.gif
 
I will assume you are using SQL Server.

Some things to try:

1. You are using reserved words for column names so surround them with []
i.e. sqlscript = "INSERT INTO Supportcall([ID],[Description],[Date],[Status],[Operator],[Action],[Customer],[Contact])...."

2. MSSQL is a pain about spacing so try ) VALUES ( instead of )VALUES(

3. If you have Query Analyzer then make the script work there first then move it to code.

4. If any of those columns are numbers then they do not need the '' around the value.

Other than those things the script looks like it should work. I hope one of these things solves your problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top