Error while uploading using OleDb
-
Hi, I am working with a program for uploading and downloading files.I am able to upload and download files with SqlConnection.But when I use OleDbConnection it shows following error while uploading the files OleDbException : "Must declare the variable '@id'." Error Code : -2147217900 {"Must declare the variable '@id'."} I am using the parameters to the insert the values.for all the parameters it shows the same kind of error. Please give your valuable Suggestions or codings Thanks Jith
-
Hi, I am working with a program for uploading and downloading files.I am able to upload and download files with SqlConnection.But when I use OleDbConnection it shows following error while uploading the files OleDbException : "Must declare the variable '@id'." Error Code : -2147217900 {"Must declare the variable '@id'."} I am using the parameters to the insert the values.for all the parameters it shows the same kind of error. Please give your valuable Suggestions or codings Thanks Jith
jithbiz0033 wrote:
Please give your valuable Suggestions or codings
Without seeing your code, it is difficult to suggest a corrective solution.
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
-
jithbiz0033 wrote:
Please give your valuable Suggestions or codings
Without seeing your code, it is difficult to suggest a corrective solution.
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
Hi, The following coding threw the error. OleDbConnection mycon = new OleDbConnection(con); OleDbCommand mycom = new OleDbCommand("insert into files (Id,FileData) values (@id,@filedata)", mycon); OleDbParameter param0= new OleDbParameter("@id",OleDbType.Guid); param0.value=id; //initially got guid in id; mycom.Parameters.Add(param0); OleDbParameter param0= new OleDbParameter("@filedata",OleDbType.VarBinary); param1.value=filedata; //initially got byte[] in filedata mycom.Parameters.Add(param1); mycon.Open(); mycom.ExecuteNonQuery(); mycon.Close(); Now I changed my coding as below. OleDbConnection mycon = new OleDbConnection(con); OleDbCommand mycom = new OleDbCommand("insert into files (Id,FileData) values (?,?)", mycon); mycom.Parameters.Add("@id", OleDbType.Guid).Value = id; mycom.Parameters.Add("@filedata", OleDbType.VarBinary, fileData.Length).Value = fileData; mycon.Open(); mycom.ExecuteNonQuery(); mycon.Close(); It is working fine.But I want to know why the first coding threw the error Thanks Jith
-
Hi, The following coding threw the error. OleDbConnection mycon = new OleDbConnection(con); OleDbCommand mycom = new OleDbCommand("insert into files (Id,FileData) values (@id,@filedata)", mycon); OleDbParameter param0= new OleDbParameter("@id",OleDbType.Guid); param0.value=id; //initially got guid in id; mycom.Parameters.Add(param0); OleDbParameter param0= new OleDbParameter("@filedata",OleDbType.VarBinary); param1.value=filedata; //initially got byte[] in filedata mycom.Parameters.Add(param1); mycon.Open(); mycom.ExecuteNonQuery(); mycon.Close(); Now I changed my coding as below. OleDbConnection mycon = new OleDbConnection(con); OleDbCommand mycom = new OleDbCommand("insert into files (Id,FileData) values (?,?)", mycon); mycom.Parameters.Add("@id", OleDbType.Guid).Value = id; mycom.Parameters.Add("@filedata", OleDbType.VarBinary, fileData.Length).Value = fileData; mycon.Open(); mycom.ExecuteNonQuery(); mycon.Close(); It is working fine.But I want to know why the first coding threw the error Thanks Jith
It may be possible that your back end database doesn't understand named parameters and uses the parameter's position instead. Also, it will prefer the
?
notation for positioning parameters rather than the@
notation.
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
-
It may be possible that your back end database doesn't understand named parameters and uses the parameter's position instead. Also, it will prefer the
?
notation for positioning parameters rather than the@
notation.
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
Hi, Thanks for the explanation.I didn't really knew that the SQL servers prefers different parameters. Thanks :cool: Jith -- modified at 0:50 Thursday 22nd March, 2007