Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to get Name of the item from id 5 to the button text and from id 5 image as button image and this is the error

"The parameterized query '(@Naziv nvarchar(8),@slika nvarchar(4000))SELECT Naziv=@Naziv,Sl' expects the parameter '@slika', which was not supplied."

What I have tried:

C#
CON.Open();
string SQLQUERY = ("SELECT Naziv=@Naziv,Slika=@slika FROM HRANA WHERE Id='5'");
CMD = new SqlCommand(SQLQUERY, CON);
CMD.Parameters.AddWithValue("@Naziv", button24.Text);
CMD.Parameters.AddWithValue("@slika", button24.Image);
int N = CMD.ExecuteNonQuery();
CON.Close();

What am I doing wrong?

and when i am trying this

C#
CON.Open();
string SQLQUERY = ("SELECT Naziv=@Naziv FROM HRANA WHERE Id='5'");
CMD = new SqlCommand(SQLQUERY, CON);
CMD.Parameters.AddWithValue("@Naziv", button24.Text);

I am not getting any value
Posted
Updated 14-Aug-17 17:06pm
v2
Comments
PIEBALDconsult 14-Aug-17 23:07pm    
Naziv=@Naziv
Wrong order for one thing.

1 solution

Start with a simpler query:
string SQLQUERY = ("SELECT Naziv FROM HRANA WHERE Id='5'");
CMD = new SqlCommand(SQLQUERY, CON);
and use a SqlDataReader or SqlDataAdapter to read the data. See here for example code: Connection open and close, how to use correctly ?[^]

But this won't work:
CMD.Parameters.AddWithValue("@slika", button24.Image);
It won't transfer the image anywhere.
See here: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^] for how to deal with images and DBs.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900