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.
Author |
Topic |
hima
Starting Member
7 Posts |
Posted - 2007-11-10 : 02:00:02
|
hi friends.....i'm using the following code to save an image to SQLSERVER2005using asp.net.i got the error message Must declare the scalar variable "@Product_ID". while running the code .please help me..its urgentcn = New System.Data.OleDb.OleDbConnection(" Provider=SQLOLEDB;SERVER=SERVER\SQLEXPRESS;UID=sa; PASSWORD=kadavan2486;DATABASE=Hard1;Persist Security Info=True;")cn.Open()cm.Connection = cncm.Parameters.Clear() cm.Parameters.Add("@Product_ID", OleDbType.BigInt, 4)cm.Parameters.Add("@Img", OleDbType.VarBinary, img.Length)cm.Parameters("@Product_ID").Value = 1cm.Parameters("@Img").Value = imgcm.CommandText = "insert into Product_Small_Image(Product_ID,Img) values(@Product_ID ,@Img)"cm.ExecuteNonQuery()cn.Close() |
|
JBelthoff
Posting Yak Master
173 Posts |
Posted - 2007-11-10 : 08:29:04
|
The error is telling you exactly what is wrong. Your SQL is this:insert into Product_Small_Image(Product_ID,Img) values(@Product_ID ,@Img) You must Declare those variables.Declare @Product_ID bigintDeclare @Img varbinary(SIZE) Then you have to set or select those variables.JBelthoff• Hosts Station is a Professional Asp Hosting Provider› As far as myself... I do this for fun! |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-11-10 : 08:47:18
|
Actually, those are declared as parameters in the sqlcommand so you should be all set. Try adding the parameters to the sqlcommand after setting the commandtext, instead of before.- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
hima
Starting Member
7 Posts |
Posted - 2007-11-12 : 04:34:28
|
quote: Originally posted by hima hi friends.....i'm using the following code to save an image to SQLSERVER2005using asp.net.i got the error message Must declare the scalar variable "@Product_ID". while running the code .please help me..its urgentcn = New System.Data.OleDb.OleDbConnection(" Provider=SQLOLEDB;SERVER=SERVER\SQLEXPRESS;UID=sa; PASSWORD=kadavan2486;DATABASE=Hard1;Persist Security Info=True;")cn.Open()cm.Connection = cncm.Parameters.Clear() cm.Parameters.Add("@Product_ID", OleDbType.BigInt, 4)cm.Parameters.Add("@Img", OleDbType.VarBinary, img.Length)cm.Parameters("@Product_ID").Value = 1cm.Parameters("@Img").Value = imgcm.CommandText = "insert into Product_Small_Image(Product_ID,Img) values(@Product_ID ,@Img)"cm.ExecuteNonQuery()cn.Close()
|
|
|
hima
Starting Member
7 Posts |
Posted - 2007-11-12 : 04:40:37
|
quote: Originally posted by hima
quote: Originally posted by hima hi friends.....i'm using the following code to save an image to SQLSERVER2005using asp.net.i got the error message Must declare the scalar variable "@Product_ID". while running the code .please help me..its urgentcn = New System.Data.OleDb.OleDbConnection(" Provider=SQLOLEDB;SERVER=SERVER\SQLEXPRESS;UID=sa; PASSWORD=kadavan2486;DATABASE=Hard1;Persist Security Info=True;")cn.Open()cm.Connection = cncm.Parameters.Clear() cm.Parameters.Add("@Product_ID", OleDbType.BigInt, 4)cm.Parameters.Add("@Img", OleDbType.VarBinary, img.Length)cm.Parameters("@Product_ID").Value = 1cm.Parameters("@Img").Value = imgcm.CommandText = "insert into Product_Small_Image(Product_ID,Img) values(@Product_ID ,@Img)"cm.ExecuteNonQuery()cn.Close()
hi firends...thanks for your suggestions...i got the answer Error was in the parameter namehere I used OLEDB connectionin OLEDB, parameter declaration is using '?' insted of '@parametername'.and parameter.add statement should be like cm.Parameters.Add("?p2", OleDbType.bigint) cm.Parameters("?P2").Value =1that was the error |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-11-12 : 08:44:09
|
If you are connecting to SQL Server in .NET, you should be using a SqlConnection and not an OledbConnection.- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
|
|
|
|
|