HAVING TROUBLE SHOWING GRIDVIEW

Chintoo Semi

Total Post:135

Points:947
Posted by  Chintoo Semi
C# 
C#
 1040  View(s)
Ratings:
Rate this:

Here is my code

public void gridshow() {

        sc.Open();

        //int custtid ;

        //custtid = (int)cidshow.SelectedItem;

        SqlDataAdapter da = new SqlDataAdapter("select Cust_id , Cust_name from Cust_master where Cust_id = '" + cidshow.SelectedItem + "'", sc);

        DataSet ds = new DataSet();

        da.Fill(ds,"Cust_master");

        custshow.DataSource = ds.Tables[0];

        sc.Close();

    }

Error raised is

(Conversion failed when converting the varchar value 'System.Data.DataRowView' to data type int.)

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Having trouble showing GridView

    Hi Chintoo,


    If your cidshow is a databound combobox, SelectedItem returns a DataRowView. You will have to extract your ID field from that object

     int custtid ;

     DateGridView custdgv = cidshow.SelectedItem;

     int custtid = Convert.ToInt(custdgv["customerId"]);

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!