简体   繁体   中英

c#.net code for retrive data from dataset or datatable object

I have created a class file. In that class file, i have created a method name as getdata of type dataset or datatable. This method is to retrieve/fetch data from database and return dataset or datatable object.

I want to display data from dataset or datatable object using combobox event into textboxes.

private void comboBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    try
    {
        DataOperation DO = new DataOperation();
        //DataSet DS = new DataSet();                                
        // DS = DO.GetCompnyDetails(Convert.ToInt32(CmBxCompanyName.Text), 
        "SelectById");     

        //txtCompanyId.Text = DS.Tables[0].Rows[0["c_id"].ToString();
        //txt_mno.Text = DS.Tables[0].Rows[0]["cont_no"].ToString();
        //txt_add.Text = DS.Tables[0].Rows[0]["address"].ToString();
        //txt_vno.Text = DS.Tables[0].Rows[0]["vat_no"].ToString();
        //txtCstNo.Text = DS.Tables[0].Rows[0]["CSTNo"].ToString();
        //txt_eid.Text = DS.Tables[0].Rows[0]["e_id"].ToString();
    }
}

private void comboBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{ 
    try
    {
        DataOperation DO = new DataOperation();
        DataTable Dt;
        Dt = DO.GetPymntDetails(Convert.ToInt32(CmBxCompanyName.Selected Index), "SelectById");

        if (Dt != null)
        {
            txtCompanyId.Text = Dt.Rows[0].ItemArray[0].ToString();
            txt_mno.Text      = Dt.Rows[0].ItemArray[1].ToString();
            txt_add.Text      = Dt.Rows[0].ItemArray[2].ToString();
            txt_vno.Text      = Dt.Rows[0].ItemArray[3].ToString();
            txtCstNo.Text     = Dt.Rows[0].ItemArray[4].ToString();
            txt_eid.Text      = Dt.Rows[0].ItemArray[5].ToString();
         }
    }
}
        if (Dt.Rows.Count > 0)
        {
            txtCompanyId.Text = Dt.Rows[0][0].ToString();
            txt_mno.Text = Dt.Rows[0][1].ToString();
            txt_add.Text = Dt.Rows[0][2].ToString();
            txt_vno.Text = Dt.Rows[0][3].ToString();
            txtCstNo.Text = Dt.Rows[0][4].ToString();
            txt_eid.Text = Dt.Rows[0][5].ToString();
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM