Snehal Bobde

Snehal Bobde

  • NA
  • 11
  • 20.3k

Problam in insertion data into table using oledb

Jan 3 2012 2:59 AM
OleDbConnection con = new OleDbConnection(ConnectionString);
  if (txt_po.Text != "" && txt_challan.Text != "" && text_Vehicleno.Text != "" && text_iwQty.Text != "" && text_iwRate.Text != "" && text_iwAmt.Text != "" && text_iwVat.Text != "" && text_iwTAmt.Text != "")
  {
  con.Open();
  string s = dateTimePicker6.Value.ToShortDateString();
  //cmd = new OleDbCommand("insert into dbo_InwardRegister(PO,Date,Name_of_Party,Challan_no,Vehicle_no,Measurement,Store_Name,Material_Description,Material_Measurement,Qty,Rate,Amount,Vat,Total_Amount) values('" + txt_po.Text + "','" + s + "','" + comb_SupplierName.SelectedValue + "','" + txt_challan.Text + "','" + text_Vehicleno.Text + "','" + txt_measurement.Text + "','" + combo_storename.SelectedValue + "','" + combo_itemname.SelectedValue + "','" + combo_itemtype.SelectedValue + "','" + text_iwQty.Text + "','" + text_iwRate.Text + "','" + text_iwAmt.Text + "','" + text_iwVat.Text + "','" + text_iwTAmt.Text + "')", con);
  cmd = new OleDbCommand("Insert into dbo_InwardRegister(po,date,name_of_party,challan_no,vehicle_no,Measurement,store_name,material_description,material_measurment,qty,rate,amount,vat,totle_amount) values('" + txt_po.Text + "','" + s + "','" + comb_SupplierName.SelectedValue + "','" + txt_challan.Text + "','" + text_Vehicleno.Text + "','" + txt_measurement.Text + "','" + combo_storename.SelectedValue + "','" + combo_itemname.SelectedValue + "','" + combo_itemtype.SelectedValue + "','" + text_iwQty.Text + "','" + text_iwRate.Text + "','" + text_iwAmt.Text + "','" + text_iwVat.Text + "','" + text_iwTAmt.Text + "') ", con);
  int n = cmd.ExecuteNonQuery();
  if (n == 1)
  {
  MessageBox.Show("data inserted successfully....");
  but_inw_RegSave.Enabled = false;
  }
  else
  {
  MessageBox.Show("insert failed");
  }

  cmd = new OleDbCommand("select * from dbo_InwardRegister", con);
  //cmd.ExecuteNonQuery();
  cmd.Connection = con;
  OleDbDataReader dr = cmd.ExecuteReader();
  DataTable dt = new DataTable();
  dt.Load(dr);
  DGV_inwardregister.DataSource = dt;

  con.Close();

Answers (3)