varun

varun

  • NA
  • 12
  • 14.8k

Binding Data to Combobox Using Stored Procedure

Dec 21 2012 1:02 AM
Hi,
I am Trying to Bind the data from data from database to combobox using a stored procedure. I am getting an Error saying:
InvalidOperationException
Fill: SelectCommand.Connection property has not been initialized.


Here is my code:
            DataTable dtTest = new DataTable();
            SqlConnection con=new SqlConnection(Helper.ConnectionString);
            con.Open();
            SqlCommand cmd=new SqlCommand();
            cmd.CommandText="GetTopInvoiceId";
            cmd.CommandType=CommandType.StoredProcedure;

            SqlDataAdapter sdaTest = new SqlDataAdapter(cmd);
            DataSet dsTest=new DataSet();
            sdaTest.Fill(dsTest);
            cmbTest.DataSource = dsTest.Tables[0];
            con.Close();

Any suggestions Pls...

Answers (5)