protected void Page_Load(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("person.mdb");
conn.Open();
string strSQL = "select * from grade";
OleDbCommand Comm = new OleDbCommand(strSQL, conn);
OleDbDataAdapter da= new OleDbDataAdapter();
da.SelectCommand = Comm;
DataSet ds = new DataSet();
da.Fill(ds, "grade");
DataView dv = new DataView(ds.Tables["grade"]);
dv.RowFilter = " 数学>80";
dv.Sort = "学号 desc,数学 desc";
Response.Write("满足条件的记录有:" + dv.Count + "条");
dg.DataSource = dv;
dg.DataBind();
conn.Close();
}
通过DataView对象的Find()方法可以对数据进行查找,如果找到了,该方法将返回所在行的索引,并可以将查找到的数据输出。{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("person.mdb");
conn.Open();
string strSQL = "select * from grade";
OleDbCommand Comm = new OleDbCommand(strSQL, conn);
OleDbDataAdapter da= new OleDbDataAdapter();
da.SelectCommand = Comm;
DataSet ds = new DataSet();
da.Fill(ds, "grade");
DataView dv = new DataView(ds.Tables["grade"]);
dv.RowFilter = " 数学>80";
dv.Sort = "学号 desc,数学 desc";
Response.Write("满足条件的记录有:" + dv.Count + "条");
dg.DataSource = dv;
dg.DataBind();
conn.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("person.mdb");
conn.Open();
string strSQL = "select * from grade";
OleDbCommand Comm = new OleDbCommand(strSQL, conn);
OleDbDataAdapter da= new OleDbDataAdapter();
da.SelectCommand = Comm;
DataSet ds = new DataSet();
da.Fill(ds, "grade");
DataView dv = new DataView(ds.Tables["grade"],"","姓名",DataViewRowState.CurrentRows);
int rowIndex = dv.Find("小张");
if (rowIndex == -1)
Response.Write("没有找到!");
else
{
Response.Write(dv[rowIndex]["姓名"].ToString() + dv[rowIndex]["数学"].ToString());
dg.DataSource = dv;
dg.DataBind();
}
conn.Close();
}
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("person.mdb");
conn.Open();
string strSQL = "select * from grade";
OleDbCommand Comm = new OleDbCommand(strSQL, conn);
OleDbDataAdapter da= new OleDbDataAdapter();
da.SelectCommand = Comm;
DataSet ds = new DataSet();
da.Fill(ds, "grade");
DataView dv = new DataView(ds.Tables["grade"],"","姓名",DataViewRowState.CurrentRows);
int rowIndex = dv.Find("小张");
if (rowIndex == -1)
Response.Write("没有找到!");
else
{
Response.Write(dv[rowIndex]["姓名"].ToString() + dv[rowIndex]["数学"].ToString());
dg.DataSource = dv;
dg.DataBind();
}
conn.Close();
}