5
Answers

Binding Data to Combobox Using Stored Procedure

varun

varun

11y
8.8k
1
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)