Home > DeveloperSection > Forums > Having trouble showing GridView
Chintoo Semi

Total Post:135

Points:947
Posted on    February-04-2014 5:28 AM

 C# C# 
Ratings:


 1 Reply(s)
 826  View(s)
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.)



Pravesh Singh

Total Post:411

Points:2881
Posted on    February-04-2014 5:54 AM

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"]);


Don't want to miss updates? Please click the below button!

Follow MindStick