C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




please give me the code....pls....


Posted Date: 20 Aug 2008      Total Responses: 3

Posted By: ramya       Member Level: Gold     Points: 1



I have a file upload control..i need to upload folder which consists of lot of images...all those images should get stored in db...how to do this in asp.net with c#...please give me the code...pls..




Responses

Author: sujatha jillela    20 Aug 2008Member Level: SilverRating:     Points: 6

Uploading an image and saving it into database

protected void save_Click(object sender, EventArgs e)
{
// create a byte[] for the image file that is uploaded
int imagelen = FileUpload1.PostedFile.ContentLength;
byte[] picbyte = new byte[imagelen];
FileUpload1.PostedFile.InputStream.Read(picbyte, 0, imagelen);
// Insert the image and image id into the database
SqlConnection conn = new SqlConnection("server=192.168.0.1;User ID=practice1;password=teamwork;database=practice");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("insert into TableImage"+"(ImageId,ImageName) values (@imageid,@pic)", conn);
cmd.Parameters.AddWithValue("@pic", picbyte);
cmd.Parameters.AddWithValue("@imageid", TextBox1.Text);
cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}
}



Author: rishika    20 Aug 2008Member Level: GoldRating:     Points: 1

see this link
http://www.aspfree.com/c/a/ASP.NET/Uploading-Images-to-a-Database--C---Part-I/



Author: jeeva    20 Aug 2008Member Level: SilverRating:     Points: 6

Hello Ramya

For this you use

Fileupload control and create a database to upload image

and create a directory at within your project directory

i think this code will be useful to you




{
con = new SqlConnection("server=localhost;database=jee;uid=sa;pwd=sa");
com = new SqlCommand("select iid from images order by iid desc", con);
//com.CommandType = CommandType.StoredProcedure;
da = new SqlDataAdapter();
da.SelectCommand = com;
dt = new DataTable();
da.Fill(dt);

if (dt.Rows.Count > 0)
{
i = Convert.ToInt32(dt.Rows[0]["iid"].ToString());
i = i + 1;
}
else
{
i = 1;
}
}
{
if (FileUpload2.HasFile)
{
//string sm = Server.MapPath("upload//" + FileUpload1.FileName);
string sm = Server.MapPath("images//" + FileUpload2.FileName);
FileUpload2.SaveAs(sm);

Label6.Text = "File Uploaded : " + FileUpload2.FileName;

}
else
{
Label6.Text = "No File Uploaded.";
}

}

{
con = new SqlConnection("server=localhost;database=jee;uid=sa;pwd=sa");
com = new SqlCommand("images_pro1", con);
com.CommandType = CommandType.StoredProcedure;
da = new SqlDataAdapter();
da.SelectCommand = com;
com.Parameters.AddWithValue("@iidp", i);
com.Parameters.AddWithValue("@pnamep", DropDownList2.SelectedItem.Text);
com.Parameters.AddWithValue("@inamep", TextBox2.Text);
com.Parameters.AddWithValue("@ipathp", FileUpload2.FileName);
com.Parameters.AddWithValue("@istatusp", S);
// com.Parameters.AddWithValue("@productId", Convert.ToInt32(Session["productId"]).ToString());
dt = new DataTable();
da.Fill(dt);

TextBox2.Text = "";
}




Post Reply
You must Sign In to post a response.
Next : How to use javascript in class file
Previous : can anyone solve this issue?
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use