c# - Populating one dataset overwrites another dataset result -


its been 2-3 hours , can't still understand why happening. need help.

i populating datagridview using dataset. there 2 tables master , detail. using 2 datasets fetch both tables datasets (also i've implemented class fetch database call class's function return dataset containing result , assign local datasets).

now happening 1st fetch detail table , check whether null etc , if not fetch second. here problem arises second gets populated 1st 1 overwrites. out of mind can't understand happening. here's code:

private void txtinvnumber_textchanged(object sender, eventargs e)     {         if (txtinvnumber.text != "")         {             try             {                 dataset dsdetail = new dataset();                 datatable dtdetail = new datatable();                 string query = "select sell.itemid 'item id',item 'item name' ,sell.quantity ,status ,credit_limit 'credit limit',"                 + "total_amount 'total amount' ,discount_allowed 'discount' ,discounted_amount 'discounted amount' , "                 + "payable_amount 'payable amount',advance 'advance paid',amount_received 'amount received', amount_receivable 'amount receivable' "                 + "from dbo.dselling_information sell  join item_infomation on  sell.itemid=it.item_id "                 + "where invoicenum = '" + txtinvnumber.text + "'";                  string query_master = "select sale_orde_date 'date', mp.cust_id,cust_name,total_quantity,total_amount,"                 + "amount_received,amount_receivable,report_status dbo.mselling_information mp join dbo.customer_information cs on mp.cust_id=cs.cust_id"                 + " invoice_num = '" + txtinvnumber.text + "'";                 dsdetail = db.func_ds(query);                 if (dsdetail != null && dsdetail.tables != null && dsdetail.tables[0].rows.count > 0)                 {                     ds2 = db.func_ds(query_master); <--here dsitem gets populated too.                     if (ds2 != null && ds2.tables != null && ds2.tables[0].rows.count > 0)                     {                         dtselldate.value = datetime.parseexact(ds2.tables[0].rows[0]["date"].tostring(), "m/dd/yyyy", cultureinfo.invariantculture);                         txtcustid.text = ds2.tables[0].rows[0]["cust_id"].tostring();                         txtcustomername.text = ds2.tables[0].rows[0]["cust_name"].tostring();                         txttotalquantity.text = ds2.tables[0].rows[0]["total_quantity"].tostring();                         txttotalamount.text = ds2.tables[0].rows[0]["total_amount"].tostring();                         txtamountrcvd.text = ds2.tables[0].rows[0]["amount_received"].tostring();                         txtamountrcvble.text = ds2.tables[0].rows[0]["amount_receivable"].tostring();                         txtreportstatus.text = ds2.tables[0].rows[0]["report_status"].tostring();                         datagridview1.autogeneratecolumns = true;                         dtdetail = dsdetail.tables[0];                         //datagridview1.datasource = db.func_ds(query).tables[0]; // dataset                         datagridview1.datasource = dtdetail;                          isdgfill = true;                     }                 }             }             catch (exception ex)             {                 messagebox.show(ex.tostring());             }         }         else         {             ds1.clear();             datagridview1.datasource = null;             datagridview1.columns.clear();             isdgfill = false;         }     } 

i tried using new keyword no luck

    datagridview1.datasource = new datatable("dtdetail"); 

also this:

    datagridview1.datasource = new dataset("dsdetail").tables[0]; 

here problem: tried direct function call on populating data:

    datagridview1.datasource = db.func_ds(query).tables[0]; 

it worked on cellclick need multiple calculations includes fetching data database whenever fetch using dataset make datasource of datagridview null.

i using different names each dataset nothing happening. please if can tell wrong i'll thankful him\her lot.

if reassigning data source of data grid view clear previous 1 .i think mistake making.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -