Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 INSERT command with the VALUES

Author  Topic 

pickron
Starting Member

6 Posts

Posted - 2006-05-02 : 15:16:14
SQL statement:

strInsert = "INSERT Product(ProductCode, ProductTitle, ProductDescription, ProductPrice) VALUES " & _
"(<%#Container.DataItem("ProductCode")%>, <%#Container.DataItem("ProductTitle")%>, <%#Container.DataItem("ProductDescription")%>, <%#Container.DataItem("ProductPrice")%>)"


The error states: Compiler Error Message: BC30205: End of statement expected.

What is the proper expression for the VALUES to be inserted from container dataitem (look above) ? I tried to put the value from the dataitem into the INSERT command.... doesn't work. Somebody suggest?


Thank you!

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-05-02 : 18:27:20
i woudl advice you declare you variables and assign the values first before using them in your SQL statment.

What language are you using ?
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-05-02 : 21:11:49
you should create an sp for this otherwise you are trying to include your parameters + value into the dsql which gives you the error


strInsert = "INSERT Product(ProductCode, ProductTitle, ProductDescription, ProductPrice) VALUES " & _
"(" & <%#Container.DataItem("ProductCode")%> & ", " & <%#Container.DataItem("ProductTitle")%> & "," & <%#Container.DataItem("ProductDescription")%> & "," & <%#Container.DataItem("ProductPrice")%> & ")"

also, before running, print or show strInsert so you'll know you're getting the right string to execute...




--------------------
keeping it simple...
Go to Top of Page

pickron
Starting Member

6 Posts

Posted - 2006-05-03 : 08:37:51
jen,

Thanks for the advice but I still get this error:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30201: Expression expected.

Source Error:



Line 33:
Line 34: strInsert = "INSERT Product(ProductCode, ProductTitle, ProductDescription, ProductPrice) VALUES " & _
Line 35: "(" & <%#Container.DataItem("ProductCode")%> & ", " & <%#Container.DataItem("ProductTitle")%> & "," & <%#Container.DataItem("ProductDescription")%> & "," & <%#Container.DataItem("ProductPrice")%> & ")"
Line 36:
Line 37: 'strInsert2 = "SELECT * FROM Product WHERE ProductCode = ' " & a & " ' "

Go to Top of Page

pickron
Starting Member

6 Posts

Posted - 2006-05-03 : 08:38:36
afrika,

I am running VB.NET and ASP.NET.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-03 : 09:28:06
enclosed your string value with single quote

strInsert = "INSERT Product(ProductCode, ProductTitle, ProductDescription, ProductPrice) VALUES " & _
"('" & <%#Container.DataItem("ProductCode")%> & "', "



KH

Go to Top of Page

pickron
Starting Member

6 Posts

Posted - 2006-05-03 : 10:54:47
KH,

Thank you for the advice.
It did put the string value into SQL but it is showing the string & <%#Container.DataItem("ProductCode")%> & but NOT the data. I want the data.
Go to Top of Page

pickron
Starting Member

6 Posts

Posted - 2006-05-03 : 11:11:07
strInsert = "INSERT Product(ProductCode, ProductTitle, ProductDescription, ProductPrice) VALUES " & _
"(' " & <%#Container.DataItem(ProductCode)%> & " ' , ' " & <%#Container.DataItem(ProductTitle)%> & " ' , ' " & <%#Container.DataItem(ProductDescription)%> & " ' , ' " & <%#Container.DataItem(ProductPrice)%> & " ')"

Now the error shows Expression expected. Show Detailed Compiler Output said
the "~" is under < for the <%#Container.DataItem(ProductCode)%>...................
Go to Top of Page

pickron
Starting Member

6 Posts

Posted - 2006-05-04 : 08:16:16
I have fixed it. I changed the parameters into assignment for values.
Go to Top of Page
   

- Advertisement -