Retriev a row from excel and extract data in strings

Apr 18 2018 1:37 AM
i am tring to use excel sheet for a small login form however i am unable to extract data from reader object.
 
This the table
User_Id Login_Email Login_Password Last_Login Access_type
xyzabc [email protected] Password
c
 
 CODE
 
string ConStr = "";
string path = Server.MapPath("Login.xlsx");
ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;ReadOnly=False;HDR=Yes;\"";
string query = "Select from [Sheet1$] where [Login_Email] ='"+TextBox1.Text+"'";
OleDbConnection conn = new OleDbConnection(ConStr);
conn.Open();
OleDbCommand cmd = new OleDbCommand(query, conn);
OleDbDataReader reader = cmd.ExecuteReader();
String UEmail = reader["Login_Email"].ToString();
String Pwd = reader["Login_Password"].ToString();
conn.Close();

Answers (2)