PDA

View Full Version : I need on this error (Must declare the scalar variable "@UserId".)


Rai_87
04-28-2008, 11:21 AM
While i was doing sql database, i encounter this problem. pls help me solve this error and i will be appriecate if u can help :)


connect.Open();
cmd.Parameters.AddWithValue("@UserId", userid);
cmd.Parameters.AddWithValue("@name", username);
cmd.Parameters.AddWithValue("@CompanyName", companyname);
cmd.Parameters.AddWithValue("@Descriptions", Descriptions);
cmd.Parameters.AddWithValue("@Products", products);
cmd.Parameters.AddWithValue("@ContactPerson", contactperson);
cmd.Parameters.AddWithValue("@Designation", designation);
cmd.Parameters.AddWithValue("@Telephone", telephone);
cmd.Parameters.AddWithValue("@Fax", fax);
cmd.Parameters.AddWithValue("@Email", email);
cmd.Parameters.AddWithValue("@Website", website);
cmd.Parameters.AddWithValue("@FileName", FileName);

MemoryStream stream = new MemoryStream();
cmd = new SqlCommand(commandString.ToString(), connect);
SqlCommand command = new SqlCommand("SELECT CompanyLogo FROM CompleteUserDetails WHERE UserId = (SELECT UserId FROM CompleteUserDetails WHERE UserName='", connect);
byte[] storedImage = (byte[])cmd.ExecuteScalar();
stream.Write(storedImage, 0, storedImage.Length);
Bitmap bitmap = new Bitmap(stream);
Response.ContentType = "Image/jpeg";
bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
cmd.Parameters.AddWithValue("@CompanyLogo", image);
cmd.ExecuteNonQuery();
connect.Close();

mjlorbet
04-28-2008, 10:32 PM
either your parameters for the procedure you're calling are out of order or you haven't defined that parameter as an actual input parameter in the stored procedure

Rai_87
04-29-2008, 03:11 AM
could u help me out on the parameter cos i am not sure where does the error come from...... btw i am new to sql database:D

mjlorbet
04-29-2008, 03:15 AM
you'd have to post the code for the stored procedure it's calling, can't really troubleshoot sql blind with that type of error

Rai_87
04-29-2008, 03:23 AM
sorrie u but inside my code does have a command call stored procedure.... can show me an example of stored procedure:p

mjlorbet
04-29-2008, 03:32 AM
basically, from what i can tell, is that your code above is getting ready to call a stored procedure, which is just a function stored in your sql database. if this wasn't your intention, then you need to research the manual for your database server (or just search through these links to see if they have any potential towards doing what you're trying to do)

http://databases.about.com/od/sqlserver/a/storedprocedure.htm
http://dev.mysql.com/doc/refman/5.0/en/stored-procedures.html
http://msdn2.microsoft.com/en-us/library/ms187926.aspx
http://msdn2.microsoft.com/en-us/library/ms190782.aspx

Rai_87
04-29-2008, 04:19 AM
thx for the valuable info, bro =D

Rai_87
04-29-2008, 04:29 AM
I think i have the stored procedure in my coding but the error still remain, can u help me see what is wrong in my coding......

Rai_87
04-29-2008, 11:52 AM
I have a new error which state that Object reference not set to an instance of an object when i debug my program. The program stop half way when i executing at stream.Write(storedImage, 0, storedImage.Length); ..... can u help me on this error