Although your question is not completely clear to us,
at first glance, your
SELECT
query is wrong.
SELECT * FROM [Sheet1$]([Country]) VALUES('"+ DropDownList1 + "')
Secondly, I assume you want to bind the dropdownlist with data from Country table just for the registration is done. It's bit a weird requirement as usually you may want to bind the dropdownlist at first page load.
So, what you should do?
First of all, remove the SELECT query completely from there. (following line)
query += "SELECT * FROM [Sheet1$]([Country]) VALUES('"+ DropDownList1 + "')";
Think twice about where you want to bind the dropdown, ideally it should be at
page_load
event & with a check for not
IsPostback
.
Following lines of code can be used to bind your dropdown with data from Country table.
OleDbConnection conn = new OleDbConnection(ConStr);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
string query = "SELECT Country FROM [Sheet1$]";
OleDbCommand cmd = new OleDbCommand(query, conn);
OleDbDataReader read = dbc.ExecuteReader();
DropDownList1.DataSource = read;
DropDownList1.DataTextField="Country";
DropDownList1.DataValueField="Country";
DropDownList1.DataBind();
read.Close();
if (conn.State == ConnectionState.Opened)
{
conn.Close();
}
One more concern, you are saving different data sets to Sheet1 of your excel file which doesn't contain Country data as it seems. So, replace with the correct sheet name.
I am not sure if my suggestion will help you much as question was not so clear. In that case please try to explain clearly about the problem and what requirement you are trying to solve by the supplied code.
Hope, it helps.
Thanks!