Design as follows
name textbox
address textbox
image fileupload
code as follows
public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
string s1;
string path;
//SqlConnection con = new SqlConnection();
SqlCommand com = new SqlCommand();
SqlDataAdapter da;
DataTable dt;
int id;
string name;
string address;
string image;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
private void bindgrid()
{
con = new SqlConnection("Server=(local);initial catalog=master;Trusted_Connection=True");
con.Open();
da = new SqlDataAdapter("select * from photo", con);
dt = new DataTable();
da.Fill(dt);
da.Dispose();
//GridView1.DataSource = dt;
//GridView1.DataBind();
con.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
con = new SqlConnection("Server=(local);initial catalog=master;Trusted_Connection=True");
if (FileUpload1.PostedFile.ContentLength > 0)
{
s1 = Path.GetFileName(FileUpload1.FileName);
path = Server.MapPath("images") + "/" + s1;
FileUpload1.SaveAs(path);
}
con.Open();
SqlCommand com = new SqlCommand("insert_employee", con);
com.CommandType = CommandType.StoredProcedure;
com.Connection = con;
com.Parameters.AddWithValue("@name", txt_name.Text);
com.Parameters.AddWithValue("@address", txt_Address.Text);
com.Parameters.AddWithValue("@image", s1);
com.ExecuteNonQuery();
bindgrid();
con.Close();
}
}
please help me.what is the error and reply me.
Dharmesh SharmaPosted Oct 3, 2012, 4:29 PM
after that insert
thanks
Dharmesh sharma
www.dharmeshsharma.com
Dorababu MekaPosted Sep 28, 2012, 3:04 AM
instead of
om.Parameters.AddWithValue("@image", s1);
try
om.Parameters.AddWithValue("@image", path);
or change as follows
then ur insert code
om.Parameters.AddWithValue("@image", s1);