I have 5 fields. serial number,category which is a dropdown list, description image upload field and cost price.
I want to add serial number,category description cost price from text box and image to be uploaded from fileupload control and get stored in database in sql server and shows in folder in visual studio.
i have written the code but its not working.
i have made serial number isidentity property to yes.
so for this at runtime fields are getting moved by 1 row. in place of category 1 getting inserted, in place of description category value getting inserted and so on and so forth.
I am sending the code.
Can anyone check and tell me please.stuck here for a long time.
Thanks In advance
public partial class AddEarRing : System.Web.UI.Page
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
protected void Button1_Click(object sender, EventArgs e)
SqlCommand cmd = new SqlCommand("insert into invent values('" + txtcode.Text + "', '" + DropDownList1.Text + "', '" + txtdesc.Text + "', '" + TextBox1.Text + "', '" + TextBox4.Text + "', '" + txtprice.Text + "')", con);
Label8.Visible = true;
Label8.Text = "Your Data Successfully added";
txtcode.Text = "";
txtdesc.Text = "";
TextBox1.Text = "";
TextBox4.Text = "";
txtprice.Text = "";
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
string path = Server.MapPath("Images/");
string ext = Path.GetExtension(FileUpload1.FileName);
if (ext == ".jpg" || ext == ".png" || ext == ".jpg")
FileUpload1.SaveAs(path + FileUpload1.FileName);
string name = "~/Images/" + FileUpload1.FileName;
string s = ("insert into invent values('" + TextBox4.Text + "'");
SqlCommand cmd = new SqlCommand(s, con);
Label9.Text = "Your file has been uploaded";
Response.Write("Please select a file");