I have single DataSet.xsd file and in this i have two DataTable one is Bill and another is BillInfo now, i am fill writing this code
string qry = "Select * from BillInfo where [BillNumber]='" +txtbill.Text + "' and [Session]='"+CLS.ses+"'";
OleDbDataAdapter da = bm.returnDataAdaptor(qry);
DataSet ds1 = new DataSet();
da.Fill(ds1);
DataSets.Bill ds = new DataSets.Bill();
da.Fill(ds);
DataTable Dt1 = ds1.Tables[0];
DataTable dt = ds.Tables.Add("BillInfo");
dt.Columns.Add("BillNumber", Type.GetType("System.String"));
dt.Columns.Add("CustomerName", Type.GetType("System.String"));
dt.Columns.Add("City", Type.GetType("System.String"));
dt.Columns.Add("Mobile", Type.GetType("System.String"));
dt.Columns.Add("TotalAmount", Type.GetType("System.String"));
dt.Columns.Add("Packing", Type.GetType("System.String"));
dt.Columns.Add("Tax", Type.GetType("System.String"));
dt.Columns.Add("Transport", Type.GetType("System.String"));
dt.Columns.Add("Additional", Type.GetType("System.String"));
dt.Columns.Add("PaybleAmount", Type.GetType("System.Int32"));
dt.Columns.Add("Session", Type.GetType("System.String"));
dt.Columns.Add("Date1", Type.GetType("System.DateTime"));
dt.Columns.Add("Naration", Type.GetType("System.String"));
dt.Columns.Add("AmountWord", Type.GetType("System.String"));
dt.Columns.Add("Status", Type.GetType("System.String"));
dt.Columns.Add("Balance", Type.GetType("System.Int32"));
for (int i = 0; i < Dt1.Rows.Count; i++)
{
DataRow r = dt.NewRow();
r["BillNumber"] = Dt1.Rows[i][0];
r["CustomerName"] = Dt1.Rows[i][1];
r["City"] = Dt1.Rows[i][2];
r["Mobile"] = Dt1.Rows[i][3];
r["TotalAmount"] = Dt1.Rows[i][4];
r["Packing"] = Dt1.Rows[i][5];
r["Tax"] = Dt1.Rows[i][6];
r["Transport"] = Dt1.Rows[i][7];
r["Additional"] = Dt1.Rows[i][8];
r["PaybleAmount"] = Dt1.Rows[i][9];
r["Session"] = Dt1.Rows[i][10];
r["Date1"] = Dt1.Rows[i][11];
r["Naration"] = Dt1.Rows[i][12];
r["AmountWord"] = Dt1.Rows[i][13];
r["Status"] = Dt1.Rows[i][14];
r["Balance"] = Dt1.Rows[i][15];
dt.Rows.Add(r);
}
string qry1 = "Select * from BillDetails where [BillNumber]='" + txtbill.Text + "'";
OleDbDataAdapter da1 = bm.returnDataAdaptor(qry1);
DataSet ds2 = new DataSet();
da.Fill(ds2);
da.Fill(ds);
DataTable Dt2 = ds2.Tables[0];
DataTable dt2 = ds.Tables.Add("Bill");
dt2.Columns.Add("BillNumber", Type.GetType("System.String"));
dt2.Columns.Add("ProductCode", Type.GetType("System.String"));
dt2.Columns.Add("ProductName", Type.GetType("System.String"));
dt2.Columns.Add("productSize", Type.GetType("System.String"));
dt2.Columns.Add("ProductQuantity", Type.GetType("System.String"));
dt2.Columns.Add("ProductWeight", Type.GetType("System.String"));
dt2.Columns.Add("Unit", Type.GetType("System.String"));
dt2.Columns.Add("ProductPrice", Type.GetType("System.String"));
dt2.Columns.Add("Amount", Type.GetType("System.String"));
dt2.Columns.Add("Date1", Type.GetType("System.DateTime"));
for (int i = 0; i < Dt2.Rows.Count; i++)
{
DataRow r = dt.NewRow();
r["BillNumber"] = Dt2.Rows[i][0];
r["ProductCode"] = Dt2.Rows[i][1];
r["ProductName"] = Dt2.Rows[i][2];
r["productSize"] = Dt2.Rows[i][3];
r["ProductQuantity"] = Dt2.Rows[i][4];
r["ProductWeight"] = Dt2.Rows[i][5];
r["Unit"] = Dt2.Rows[i][6];
r["ProductPrice"] = Dt2.Rows[i][7];
r["Amount"] = Dt2.Rows[i][8];
r["Date1"] = Dt2.Rows[i][9];
dt2.Rows.Add(r);
}
but at the r["ProductCode"] = Dt2.Rows[i][1]; it is showing an exception. That is Column 'ProductCode' does not belong to table BillInfo. Please solve my error.
Replace
with
You have simply used the wrong table which has no column
ProductCode. It must be “Bill” instead of “BillInfo”.Apart from that:
You are open for sql-injection when you use textboxes as input for your sql query. Use parameters instead.
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbparameter.aspx