I am trying to get data from the SQL database with stored procedure using dataset and populate that data in combobox. It gives error as cannot find table 0.
SqlConnection conn = new SqlConnection();
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString;
SqlCommand cmd2 = new SqlCommand("GetBatch", conn);
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.CommandText = "usp_CAMR_GetBatch_Status";
cmd2.Connection = conn;
cmd2.Parameters.AddWithValue("@batch_name", comboBox1.Text.ToString().Substring(0, 12));
cmd2.Parameters.AddWithValue("@batch_status_flg", "");
cmd2.Parameters.AddWithValue("@BATCH_STATUS_DT", "");
cmd2.Parameters.AddWithValue("@BEGIN_SFN", "");
cmd2.Parameters.AddWithValue("@END_SFN", "");
cmd2.Parameters.AddWithValue("@TOTAL_SFN", "");
cmd2.Parameters.AddWithValue("@TOTAL_AMEND", "");
cmd2.Parameters.AddWithValue("@TOTAL_PAGES", "");
cmd2.Parameters.AddWithValue("@lst_mod_userid", "");
cmd2.Parameters.AddWithValue("@lst_mod_dt", "");
cmd2.Parameters.AddWithValue("@ERR_CODE", 0);
cmd2.Parameters.AddWithValue("@ERR_MSG", 0);
cmd2.Parameters.AddWithValue("@TABLE_NAME", "");
cmd2.Parameters.AddWithValue("@batch_status_msg", "");
//cmd2.CommandText = @"select batch_name, batch_status_flg from camr_batch_control";
try
{
conn.Open();
SqlDataAdapter dapt = new SqlDataAdapter(cmd2);
dapt.Fill(ds5);
for (int z = 0; z < comboBox1.Items.Count; z++)
{
for (int a = 0; a < ds5.Tables[0].Rows.Count; a++)
{
if (comboBox1.Items[z].ToString() == ds5.Tables[0].Rows[a][0].ToString())
{
comboBox1.Items.Add(comboBox1.Items[z] + " - " + ds5.Tables[0].Rows[a][1].ToString());
comboBox1.Items.Remove(comboBox1.Items[z]);
}
}
}
}
}
catch (Exception ex)
{
if (lblerror.Text == "")
{
lblerror.Text = ex.Message;
}
else
{
lblerror.Text = lblerror.Text + ex.Message;
}
}
finally
{
conn.Close();
conn.Dispose();
}