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
04-Feb-2014If 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"]);