Here we are uploading images in File System and storing path in the database.
Code (ImageUpload.as px.cs) :-
[CODE=vb]private void Button1_Click(o bject sender, System.EventArg s e)
{
// Here I am uploading images in Images folder of C drive.
int intResult=0;
string strPath = @"c:\Images\"+P ath.GetFileName (File1.PostedFi le.FileName);
SqlConnection con = new SqlConnection(" server=.;uid=sa ;database=pubs; pwd=");
SqlCommand com = new SqlCommand("Ins ert into Category(name,i magepath) values(@name,@i magepath)",con) ;
com.Parameters. Add("@name",Tex tBox1.Text);
com.Parameters. Add("@imagepath ",strPath);
con.Open();
intResult = Convert.ToInt32 (com.ExecuteNon Query());
if(intResult != 0)
{
File1.PostedFil e.SaveAs(strPat h);
Response.Write( "Record Inserted.");
}
}[/CODE]
Code (ImageUpload.as px.cs) :-
[CODE=vb]private void Button1_Click(o bject sender, System.EventArg s e)
{
// Here I am uploading images in Images folder of C drive.
int intResult=0;
string strPath = @"c:\Images\"+P ath.GetFileName (File1.PostedFi le.FileName);
SqlConnection con = new SqlConnection(" server=.;uid=sa ;database=pubs; pwd=");
SqlCommand com = new SqlCommand("Ins ert into Category(name,i magepath) values(@name,@i magepath)",con) ;
com.Parameters. Add("@name",Tex tBox1.Text);
com.Parameters. Add("@imagepath ",strPath);
con.Open();
intResult = Convert.ToInt32 (com.ExecuteNon Query());
if(intResult != 0)
{
File1.PostedFil e.SaveAs(strPat h);
Response.Write( "Record Inserted.");
}
}[/CODE]
Comment