Hi Jkahir,
I have updated the code. Refer updated code.
C#
using System;
using System.Data;
using System.Data.OleDb;
using System.Web.UI.WebControls;
public partial class user_Viewproduct : System.Web.UI.Page
{
string conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\\jayesh\\fjayesh.mdb";
OleDbConnection con, conInsert;
string str;
OleDbCommand cmd, cmd1, cmdInsert;
int oid;
protected void Page_Load(object sender, EventArgs e)
{
using (con = new OleDbConnection(conString))
{
string str = "select * from user_data where username='" + Session["usernm"].ToString() + "' and pass='" + Session["pass1"].ToString() + "'";
using (cmd1 = new OleDbCommand(str, con))
{
con.Open();
OleDbDataReader dr1 = cmd1.ExecuteReader();
if (dr1.Read())
{
oid = int.Parse(dr1["o_id"].ToString());
Session["moid"] = oid.ToString();
}
con.Close();
}
}
if (!IsPostBack)
{
bnd2();
}
}
protected void bnd2()
{
str = "select * from product ";
OleDbDataAdapter da = new OleDbDataAdapter(str, con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView3.DataSource = ds;
GridView3.DataBind();
}
protected void GridView3_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView3.PageIndex = e.NewPageIndex;
bnd2();
}
protected void GridView3_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void btnbackviewproduct_Click(object sender, EventArgs e)
{
Response.Redirect("~/user/Home.aspx");
}
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "order")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView3.Rows[index];
Label l = (Label)row.FindControl("lblfid");
Label P1 = (Label)row.FindControl("lblfprice");
TextBox t = (TextBox)row.FindControl("txtqty");
TextBox td1 = (TextBox)row.FindControl("TextBox1");
Session["pid"] = l.Text;
string str1 = "select * from product where p_id=" + l.Text;
using (con = new OleDbConnection(conString))
{
using (cmd = new OleDbCommand(str1, con))
{
con.Open();
using (OleDbDataReader dr = cmd.ExecuteReader())
{
if (dr.Read())
{
string pname = dr["p_name"].ToString();
int pr = int.Parse(dr["price"].ToString());
td1.Text = DateTime.Today.ToString("yyyy-MM-dd");
str = "insert into orders(o_id,p_id,name,amount,quantity,date_time) values(" + oid + "," + l.Text + ",'" + pname + "'," + pr + "," + t.Text + ",'" + td1.Text + "')";
using (OleDbConnection conInsert = new OleDbConnection())
{
OleDbCommand cmdInsert = new OleDbCommand(str, conInsert);
conInsert.Open();
int i = cmdInsert.ExecuteNonQuery();
conInsert.Close();
if (i > 0)
{
Response.Write("<script> alert('inserted succsess..') </script>");
}
else
{
Response.Write("<script> alert(' not inserted succsess..') </script>");
}
}
}
}
con.Close();
}
}
Response.Redirect("~/user/vieworder.aspx");
}
}
}