using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.IO;
using System.Data;
public partial class admin_AddminItem : System.Web.UI.Page
{
OleDbConnection con;
OleDbCommand com;
string str;
public admin_AddminItem()
{
new_id();
}
protected void Page_Load(object sender, EventArgs e)
{
}
private void new_id()
{
if (con.State != ConnectionState.close)
{
con.Open();
}
str = "select max(admin_create_id) from Itm_tbl";
com = new OleDbCommand(str, con);
com.CommandType = CommandType.Text;
Int32 max = (Int32)com.ExecuteScalar();
Label3.Text = (max + 1).ToString();
con.Close();
}
protected void Button9_Click(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
{
{
con.Open();
}
con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\ahb\Desktop1\App_Data\amit_db.mdb");
string str = FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Upload/" + str));
string Image = "~/Upload/" + str.ToString();
string cat_name = DropDownList1.SelectedValue.ToString();
OleDbCommand cmd = new OleDbCommand("insert into Itm_tbl values(@admin_create_id, @name , @desc , @price , @qty , @img , @cat )", con);
com.Parameters.AddWithValue("@admin_create_id", Label3.Text);
cmd.Parameters.AddWithValue("@name",txtiname.Text );
cmd.Parameters.AddWithValue("@desc",txtdescrip.Text );
cmd.Parameters.AddWithValue("@price",int.Parse(txtprice.Text) );
cmd.Parameters.AddWithValue("@qty", int.Parse(txtquan.Text));
cmd.Parameters.AddWithValue("@img",Image );
cmd.Parameters.AddWithValue("@cat",cat_name );
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Label1.Text = "Item added";
Label1.ForeColor = System.Drawing.Color.ForestGreen;
new_id();
}
else
{
Label1.Text = "Please Upload your Image";
Label1.ForeColor = System.Drawing.Color.Red;
}
}
protected void txtdescrip_TextChanged(object sender, EventArgs e)
{
}
}