By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

Fetching multiple images from database

P: 22
Hi to All Senior's,
I am working in Asp.net with C#. I am newbie in C#. So i want to fetch mutiple images from database .Database i am using is Sql Server.
For this i code:

//get the image id from the url
string Imagename = DropDownList1.SelectedItem .Text ;
//string Imagename = Request.QueryString["DropDownList1.SelectedItem.Value"];

//build our query statementworkstation id=SOFTWARE3;packet size=4096;integrated security=SSPI;data source=SOFTWARE3;persist security info=True;initial catalog=farmergroup
string sqlText = "SELECT Image FROM images WHERE Name='"+Imagename+"'";

SqlConnection connection = new SqlConnection("workstation id=SOFTWARE3;packet size=4096;integrated security=SSPI;data source=SOFTWARE3;persist security info=True;initial catalog=farmergroup");
SqlCommand command = new SqlCommand( sqlText, connection);

//open the database and get a datareader
connection.Open();
SqlDataReader dr;
dr = command.ExecuteReader();
while (dr.Read()) //yup we found our image
{
//Response.ContentType = dr["img_contenttype"].ToString();
Response.BinaryWrite((byte[])dr["Image"]);
}
connection.Close();

}
}
This is fetching only one image.but i want fetch more image.Please check it.
Please help me as i am new in c#.
Thanks & Regards.
Punit Shrivastava.
Nov 6 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.