Hey there.... I'm trying to learn VS.Net 2008 on my own. It seems very much like an up hill climb without a rope. I'm trying to save the results I've calculated to a SQL Server 2008 MDF file. I've called this simple DB DBTest and it only has two fields (columns). The first is the primary key and its called StockIndex (int, No Nulls) and the second is called StockSymbol (nchar(10), Allows Nulls). I've been lead to believe that the INSERT command is well suited for what I want to do, but I keep getting the same error! ...and its getting to me! The error message is: Incorrect syntax near '?'. Any help you can give would be greatly appreciated! May each of you have a blessed day as the Lord wills. John Here's an example of my code:
You usually use the @ sign for params in SQL Server - like this INSERT INTO DBTest (StockIndex, StockSymbol) VALUES (@StockIndex, @StockSymbol)
Hi .... I'm still getting errors when the program gets to this line. I was thinking of changing the above line from Dim SQL_Command As New SqlClient.SqlCommand("INSERT INTO DBTest (StockIndex, StockSymbol) VALUES (?, ?)", SQL_Connection) to use single quote around the column names like in this: Dim SQL_Command As New SqlClient.SqlCommand("INSERT INTO DBTest ('StockIndex', 'StockSymbol') VALUES (?, ?)", SQL_Connection) What should I expect? God bless JEP_Dude
chanda .... Thanks for your assistance. Yet, I'm new with SQL. So please forgive me for asking but, what do you mean when you said, "... put the parameters into single quotes and then in inverted comas". To clarify, would you please give me an example of wht you mean with the line below? Dim SQL_Command As New SqlClient.SqlCommand("INSERT INTO DBTest ('StockIndex', 'StockSymbol') VALUES (?, ?)", SQL_Connection) Thanks in advance. May you, as well as those listening, have a blessed day as the Lord wills. JEP_Dude
i m not sure but u should do one of the followings... 1.put stockindex into inverted comas and stock symbol into single quotes and then in inverted comas such as ("Stockindex",'"StockSymbol"') 2.or put first ?in to inverted comas and second ? into single quotes and then into inverted comas as given in above e.g 3.if both two steps given is not worked than do both steps simultaneously.... and note one thing parameters of int always come in inverted comas and parameters for char comes in single quotes then in inverted comas
You can try out this... Dim SQL_Command As New SqlClient.SqlCommand("INSERT INTO DBTest ('StockIndex', 'StockSymbol') VALUES ("& G_StockIndex)&", "& G_Stock(1, 1).Symboll &")", SQL_Connection)
Hey there ...! I've tried a suggestion given before and it works well! It was suggested that I follow the older approach given within SQL 2005. Yet, the question does remain of, how much of SQL 2005 is still valid within SQL 2008? If each command of the previous version still works, then why change anything? May you have a blessed day as the Lord wills. JEP_Dude