using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = sqlconn1().Tables["donkey"].DefaultView;
GridView1.DataBind();
GridView2.DataSource = sqlconn2();
GridView2.DataBind();
GridView3.DataSource = sqlaccess();
GridView3.DataBind();
GridView4.DataSource = sqlexcel();
GridView4.DataBind();
}
}
public DataSet sqlconn1()
{
SqlConnection conn = new SqlConnection("data source=(local);database=monkey;uid=monkey;pwd=donkey");
SqlDataAdapter database = new SqlDataAdapter("select * from donkey", conn);
DataSet ds = new DataSet();
conn.Open();
database.Fill(ds, "donkey");
conn.Close();
return ds;
}
public DataTable sqlconn2()
{
SqlConnection conn = new SqlConnection("data source=(local);database=monkey;uid=monkey;pwd=donkey");
SqlCommand cmd = new SqlCommand("select * from houzi", conn);
SqlDataReader sdr = null;
conn.Open();
sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(sdr);
return dt;
}
public DataSet sqlaccess()
{
OleDbConnection conn = new OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source=" + Server.MapPath("monkey.mdb") + "");
OleDbDataAdapter database = new OleDbDataAdapter("select * from donkey", conn);
DataSet ds = new DataSet();
conn.Open();
database.Fill(ds, "donkey");
return ds;
}
public DataSet sqlexcel()
{
OleDbConnection conn = new OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source=" + Server.MapPath("book1.xls") + ";Extended Properties=Excel 8.0");
OleDbDataAdapter database = new OleDbDataAdapter("select * from [sheet1$]", conn);
DataSet ds = new DataSet();
conn.Open();
database.Fill(ds);
conn.Close();
return ds;
}
}