|
-
December 3rd, 2004, 04:13 AM
#1
Help Needed Regarding DataSet
Hi, im having this problem. I have a DropDownList with a list of values. It consist of AdminNumbers. I manually added a All option in the dropdownlist. When i click all it suppose to display all the AdminNumbers's details In a datagrid. Im trying to use a Foreach loop make this thing work. But the problem lies in here. Below is the code(The part which executes the "All" selection in the dropdownlist).
Code:
foreach(ListItem li in AdminList.Items)
{
string tryy;
tryy = li.Value.ToString();
SqlCommand cmd = sqlConnection1.CreateCommand();
cmd.CommandText = "SELECT * FROM AttendanceAdmin.atten WHERE AdminNo=@AdminNo";
cmd.Parameters.Add(new SqlParameter("@DateFrom", SqlDbType.VarChar, 50));
cmd.Parameters.Add(new SqlParameter("@AdminNo", SqlDbType.VarChar, 50));
cmd.Parameters.Add(new SqlParameter("@DateTo", SqlDbType.VarChar, 50));
cmd.Parameters["@DateFrom"].Value = Date1tb.Text.ToString();
cmd.Parameters["@AdminNo"].Value = tryy;
cmd.Parameters["@DateTo"].Value = Date2tb.Text.ToString();
SqlDataAdapter sqladapter = new SqlDataAdapter();
sqladapter.SelectCommand = cmd;
DataSet myDataSet = new DataSet();
sqlConnection1.Open();
sqladapter.Fill(myDataSet, "atten");
sqlConnection1.Close();
DataGrid5.DataSource = myDataSet;
DataGrid5.DataBind();
}
The above code is the one i tried out. But it doesn't work. It resets the dataset each time it loops so the output is always the last value in the dropdownlist. Can anyone give me a tip or two, to make the dataset stacks the values it receives from the SELECT statement. Then when the loop ended, it binds the dataset to the datagrid to display the result.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|