Hi
Here I post my Code for Depends for Excel sheet For Sql server Database
1. Register page add the Excel sheet our Login Details.
2.Login.aspx -> when user Login check the data Goes following Page.
Register.aspx
===============
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Data.OleDb;
public partial class Default2 : System.Web.UI.Page
{
OleDbConnection con;
OleDbCommand com;
string str;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Cmd_Register_Click(object sender, EventArgs e)
{
try
{
//DataTable dt1 = new DataTable();
//dt1 = dtBind();
//if (Convert.ToInt32(dt1.DefaultView[0][0]) == 1)
//{
com = new OleDbCommand();
con = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='d:\\test.xls';Extended Properties=Excel 8.0;");
con.Open();
com.Connection = con;
str = "Insert into [sheet1$] (EID,UserName,Password) values('" + '1' + "','" + TxtUserName.Text + "','" + TxtPassword.Text + "')";
com.CommandText = str;
com.ExecuteNonQuery();
con.Close();
//}
}
catch (Exception ex)
{
}
}
private DataTable dtBind()
{
DataTable dt = new DataTable();
com = new OleDbCommand();
con = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='d:\\test.xls';Extended Properties=Excel 8.0;");
con.Open();
com.Connection = con;
str = "Select count(*) from [sheet1$]";
OleDbDataAdapter oleda = new OleDbDataAdapter(str, con);
oleda.Fill(dt);
return dt;
}
}
Login.aspx
=================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
public partial class FrmLogin : System.Web.UI.Page
{
OleDbConnection con;
OleDbCommand com;
string str;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Cmd_Submit_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
com = new OleDbCommand();
con = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='d:\\test.xls';Extended Properties=Excel 8.0;");
con.Open();
com.Connection = con;
str = "Select * from [sheet1$]";
OleDbDataAdapter oleda = new OleDbDataAdapter(str, con);
oleda.Fill(dt);
DataRow[] dr;
dr = dt.Select("UserName='Jesus' and Password='jesus'");
if (dr.Length > 1)
{
Response.Redirect("Home.aspx");
}
}
}