How do I create a drop down list which has the values from a database column. So I need this list to have values like"
"Select distinct departmentname from Department"
The Department name should show in the drop down list and I should be able to select one department name from the list.
This is my code for read the column name from an excet test11.xls.now i want to fetch the dataset to that column name departmant.
please help.
[code=cpp]
string filePath1 = Server.MapPath( "test11.xls ");
da = new SqlDataAdapter ("select departmentname from departmentmaste r", con);
ds = new DataSet();
da.Fill(ds);
DataTable columns;
string[] restrictions = { null, null, "Data$", null };
//string connectionStrin g = @"Provider=Micr osoft.Jet.OLEDB .4.0; Data Source=Book1.xl s;Extended Properties=""Ex cel 8.0;HDR=YES;""" ;
string connectionStrin g = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" + filePath1 + ";Extended Properties=\"Ex cel 8.0;HDR=YES;IME X=1;\"";using (OleDbConnectio n connection = new OleDbConnection (connectionStri ng))
{
connection.Open ();
columns = connection.GetS chema("Columns" , restrictions);
String[] excelSheets = new String[columns.Rows.Co unt];
int iwork = 0;
// Add the sheet name to the string array.
foreach (DataRow row in columns.Rows)
{
excelSheets[iwork] = row["Column_NAM E"].ToString();if (excelSheets[iwork] == "Department ")
{
// Here how can i fetch that dataset to the column Department
}
iwork++;
}
}[/code]
"Select distinct departmentname from Department"
The Department name should show in the drop down list and I should be able to select one department name from the list.
This is my code for read the column name from an excet test11.xls.now i want to fetch the dataset to that column name departmant.
please help.
[code=cpp]
string filePath1 = Server.MapPath( "test11.xls ");
da = new SqlDataAdapter ("select departmentname from departmentmaste r", con);
ds = new DataSet();
da.Fill(ds);
DataTable columns;
string[] restrictions = { null, null, "Data$", null };
//string connectionStrin g = @"Provider=Micr osoft.Jet.OLEDB .4.0; Data Source=Book1.xl s;Extended Properties=""Ex cel 8.0;HDR=YES;""" ;
string connectionStrin g = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" + filePath1 + ";Extended Properties=\"Ex cel 8.0;HDR=YES;IME X=1;\"";using (OleDbConnectio n connection = new OleDbConnection (connectionStri ng))
{
connection.Open ();
columns = connection.GetS chema("Columns" , restrictions);
String[] excelSheets = new String[columns.Rows.Co unt];
int iwork = 0;
// Add the sheet name to the string array.
foreach (DataRow row in columns.Rows)
{
excelSheets[iwork] = row["Column_NAM E"].ToString();if (excelSheets[iwork] == "Department ")
{
// Here how can i fetch that dataset to the column Department
}
iwork++;
}
}[/code]