|
-
December 7th, 2004, 07:40 PM
#7
Re: Help Needed Regarding DataSet
I've did try out the code you given me. I've edited it to suit my program. But the result is isn't what i wanted. It display the whole database if -All- is selected. What i wanted and needed is when -All- is selected, it ONLY displays the admin number's details IN the DropDownList of admin numbers and not the whole database.
Therefore i needed a foreach loop, to loop the SQL query of the database for each admin number in the dropdownlist. After query, it adds the result into a dataset (Stacks the query results in the dataset depend on number of admin numbers in the dropdownlist) Then bind it into a datagrid.
I know how it could be done but i lack the programming skill to actually write the code out. Therefore im seeking help for experience programmers. I didn't really expect others to write the code for me and i just paste it into my code and be a happy man. An example of how it could be done would be enough. Im willing to learn and trying to learn, if i don't even bother i won't even be asking question on how the code work and what does the code means etc.. thanks for your time in replying to my post though.. i really appreciate it.
Below is the code which you gave me, i edited it a little in order to make it run.
Code:
private void AdminList_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(AdminList.SelectedValue=="All")
{
SqlCommand cmd = sqlConnection1.CreateCommand();
cmd.CommandText = "SELECT * FROM AttendanceAdmin.atten";
SqlDataAdapter sqladapter = new SqlDataAdapter();
sqladapter.SelectCommand = cmd;
DataSet myDataSet = new DataSet();
sqlConnection1.Open();
sqladapter.Fill(myDataSet, "atten");
sqlConnection1.Close();
DataGrid5.DataSource = myDataSet;
DataGrid5.DataBind();
}
else
{
StringBuilder builder = new StringBuilder();
builder.Append("SELECT * FROM AttendanceAdmin.atten WHERE AdminNo =");
builder.Append("'");
builder.Append(AdminList.SelectedValue.ToString());
builder.Append("'");
SqlCommand cmd = new SqlCommand( builder.ToString(), sqlConnection1);
SqlDataAdapter sqladapter = new SqlDataAdapter();
sqladapter.SelectCommand = cmd;
DataSet myDataSet = new DataSet();
sqlConnection1.Open();
sqladapter.Fill(myDataSet, "atten");
sqlConnection1.Close();
DataGrid5.DataSource = myDataSet;
DataGrid5.DataBind();
}
}
Last edited by Eradicate; December 8th, 2004 at 12:06 AM.
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
|