Click here to Skip to main content
15,891,684 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I have one Table FileUploade Which contain id,userid,imageName pls help me to retrive the image namefrom table which userid is same,pls help me to write sql query for retrive ImageName From Image.
Posted
Updated 24-Dec-14 19:34pm
v2
Comments
Sergey Alexandrovich Kryukov 25-Dec-14 0:03am    
What have you tried so far? What's your problem? What prevents you from doing it? Note that you did not provide any detail on the way the image and other data is stored.
—SA
Member 11242168 25-Dec-14 0:09am    
I have stores id,ImageName,UserId relates to image in the FileUploade Table Now i want list of those user which user id is same.

1 solution

Try to do some research,
Refer this link,Here you can find how to use where clause with select statement.
http://www.w3schools.com/sql/sql_where.asp[^]

(Or)
try like this,
SQL
declare @user_id=1;
select image_name from your_table_name where userid=@user_id

declare @user_id=2;
select image_name from your_table_name where userid=@user_id

declare @user_id=3;
select image_name from your_table_name where userid=@user_id


Edit:
I make some little bit change in your code,try like this.
C#
string query1 = "select ImageName from FileUploads where UserId=@ID ";
SqlCommand cmd1 = new SqlCommand(query1, con);
cmd1.CommandType = CommandType.Text;
cmd1.Parameters.AddWithValue("@ID", User.UserId);
con.Open();
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataTable dt= new DataTable();
ad.Fill(dt);

Debug it,and check the datatable values.It will give you a list of imageName where id equals.
And bind datatable value where you want in your code.
 
Share this answer
 
v3
Comments
Member 11242168 25-Dec-14 0:20am    
No sir its not working below id my code pls check it and suggest any improvement if have.
string query1 = "select ImageName from FileUploads where UserId=@ID ";
SqlCommand cmd1 = new SqlCommand(query1, con);
cmd1.CommandType = CommandType.Text;
cmd1.Parameters.AddWithValue("@ID", User.UserId);
con.Open();
string img = Convert.ToString(cmd1.ExecuteScalar());
Response.Write(img);
ViewBag.Image = img;
Response.Write(ViewBag.Image);
Rajesh waran 25-Dec-14 0:24am    
tell me what you want to do? you try to retrive imagename from table.where u want to bind it?
Member 11242168 25-Dec-14 0:31am    
I am stor image with its name in images foldes im my project and trying to retrive by using is name
Rajesh waran 25-Dec-14 0:23am    
May i know you are using scalar? do u know what are the uses of scalar?
Member 11242168 25-Dec-14 0:27am    
sir i am also use ExecuteNonQuery but its not work my fnd suggest me to use scalar then i will use it..but is also not work pls sir guide me..

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