Insert Image with Data in Data Base Useing Asp.net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class addproduct : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=(local);Initial Catalog=Mob;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
Label1.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string strname = FileUpload1.FileName.ToString();
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/image/") + strname);
con.Open();
SqlCommand cmd = new SqlCommand("insert into Table_1 values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + strname + "','" + DropDownList1.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "')", con);
cmd.ExecuteNonQuery();
con.Close();
Label1.Visible = true;
Label1.Text = "Record Uploaded successfully!!!";
}
else
{
Label1.Visible = true;
Label1.Text = "Plz upload the Record!!!!";
}
}
}
By: Arpit Upadhyay