Kishore Konatham

Kishore Konatham

  • NA
  • 63
  • 6.8k

Can not display interface method result data in datagridview

Jul 25 2019 1:57 AM
  1. namespace WindowsFormsApplication3 {  
  2.  public partial class MyCarsForm1: {  
  3.   public MyCarsForm1() {  
  4.    InitializeComponent();  
  5.    cmbSelectCar.Items.Add("Auston MartinDB11");  
  6.   }  
  7.   
  8.   interface IDB11 {  
  9.    void DB11Specifications();  
  10.   }  
  11.   
  12.   public class AustonMartin: MyCarsForm1,  
  13.   IDB11 {  
  14.   
  15.    void IDB11.DisplaySpecifications() {  
  16.     DataSet ds = new DataSet();  
  17.     DataTable dt1 = new DataTable();  
  18.     string c = @ "Data Source=.; Initial Catalog=master; Integrated                                                                               Security=True";  
  19.     SqlConnection con = new SqlConnection(c);  
  20.     con.Open();  
  21.     string query = "select * from AustonMartinDB11 ";  
  22.     SqlCommand cmd = new SqlCommand(query, con);  
  23.     SqlDataAdapter da = new SqlDataAdapter(cmd);  
  24.   
  25.     da.Fill(ds, query);  
  26.     dgvSpecifications.DataSource = ds;  
  27.    }  
  28.   }  
  29.   
  30.   
  31.   private void cmbSelectCar_SelectedIndexChanged(object sender, EventArgs e) {  
  32.    IDB11 am = new AustonMartin();  
  33.    am.DisplaySpecifications();  
  34.    if (cmbSelectCar.SelectedIndex == 0) {  
  35.     am.DisplaySpecifications();  
  36.    }  
  37.   }  
  38.  }  
  39. }  
// On selecting first index of the combobox, it is displaying empty datagridview.
// On checking by the break point, it is loading the data in the datagridview.

Answers (1)