I created a program and one of its function is when you select an item from the dropdownlist, the data from database will automatically populate to the textbox. I have 16 texboxes and problem was, when I click the a selection, only 1 data from the DB will populate to the 16 textboxes. To help me explain clearly, please see the attached picture of my codes and DB. By the way, I am only a novice in programming. Thanks you in advance.
Loading

Jisny AvRank #4,868 · 321 reputationPosted Sep 15, 2016, 10:11 PM EDT
{
using (SqlConnection SqlCn = DBConnection.GetDbCon())
{
String strQuery = "select HPAPlan, Amount from tblHPACoverageBenefits where HPAPlan = @HPAPlan";
SqlCommand cmd = new SqlCommand();
cmd.Parameters.AddWithValue("@HPAPlan", ddlHPACoverage.SelectedItem.Text);
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = SqlCn;
try
{
SqlCn.Open();
// SqlDataReader sdr = cmd.ExecuteReader();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = null;
adapter.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TextBox txtCoverageBenefit = (TextBox)Page.FindControl("txtCoverageBenefit" + i);
txtCoverageBenefit.Text = ds.Tables[0].Rows[i]["Amount"].ToString();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
SqlCn.Close();
SqlCn.Dispose();
}
}
}
Nitin SontakkeRank #264 · 9.6K reputationPosted Sep 15, 2016, 11:15 PM EDT
Midhun TpRank #388 · 6.5K reputationPosted Sep 15, 2016, 9:49 PM EDT
Vaibhav DeshmukhRank #5,346 · 302 reputationPosted Sep 15, 2016, 9:54 PM EDT
Jes SieRank #1,285 · 1.3K reputationPosted Sep 15, 2016, 10:43 PM EDT
Jes SieRank #1,285 · 1.3K reputationPosted Sep 15, 2016, 10:46 PM EDT
Server Error in '/' Application.
Value cannot be null.
Parameter name: dataSet
Jes SieRank #1,285 · 1.3K reputationPosted Sep 15, 2016, 11:01 PM EDT
Midhun T PI tried your suggestion but I got only this result
Jes SieRank #1,285 · 1.3K reputationPosted Sep 15, 2016, 11:32 PM EDT
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Sep 15, 2016, 11:34 PM EDT
Nitin SontakkeRank #264 · 9.6K reputationPosted Sep 15, 2016, 11:43 PM EDT
Nitin SontakkeRank #264 · 9.6K reputationPosted Sep 15, 2016, 11:46 PM EDT
Jisny AvRank #4,868 · 321 reputationPosted Sep 16, 2016, 12:15 AM EDT
txtCoverageBenefit.Text = ds.Tables[0].Rows[i]["Amount"].ToString();
Jes SieRank #1,285 · 1.3K reputationPosted Sep 16, 2016, 10:49 PM EDT
Nitin SontakkeRank #264 · 9.6K reputationPosted Sep 17, 2016, 8:55 PM EDT
Delpin Susai RajRank #53 · 29.5K reputationPosted Sep 17, 2016, 11:08 PM EDT
Jes SieRank #1,285 · 1.3K reputationPosted Sep 18, 2016, 6:08 PM EDT
Nitin Sontakkeif you were able to read the question I posted, I emphasize that I am novice in C# programming. I learned only by tutorials and forums like this. A detailed instruction will help me a lot. Anyway, thanks for the advice though.
Jes SieRank #1,285 · 1.3K reputationPosted Sep 18, 2016, 7:20 PM EDT
Esakki MuthuRank #5,293 · 304 reputationPosted Sep 19, 2016, 10:20 PM EDT
Jes SieRank #1,285 · 1.3K reputationPosted Sep 21, 2016, 5:10 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts