方法:
public DataSet getRecentNdocument(int N,string wherestring)
{
OleDbConnection dbconn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data source=d:\Recent.mdb;Persist Security Info=False");
OleDbCommand cmd = dbconn.CreateCommand();
cmd.CommandText="select * from RecentDocument where ("+wherestring+")";
cmd.CommandType=CommandType.Text;
OleDbDataAdapter oda = new OleDbDataAdapter();
oda.SelectCommand = cmd;
DataSet ds = new DataSet();
oda.Fill(ds,"RecentDocument");
return ds;
}
调用:
private void button3_Click(object sender, System.EventArgs e)
{
RecentDocument bb=new RecentDocument();
DataSet ff=bb.getRecentDocument("Name='aa'");
dataGrid1.DataSource = ff;
dataGrid1.DataMember = ff.Tables[0].TableName;
}在Button3的单击事件调用那个方法,可是显示的只有字段,没有记录,这个表里是有记录的,请大家指点!
public DataSet getRecentNdocument(int N,string wherestring)
{
OleDbConnection dbconn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data source=d:\Recent.mdb;Persist Security Info=False");
OleDbCommand cmd = dbconn.CreateCommand();
cmd.CommandText="select * from RecentDocument where ("+wherestring+")";
cmd.CommandType=CommandType.Text;
OleDbDataAdapter oda = new OleDbDataAdapter();
oda.SelectCommand = cmd;
DataSet ds = new DataSet();
oda.Fill(ds,"RecentDocument");
return ds;
}
调用:
private void button3_Click(object sender, System.EventArgs e)
{
RecentDocument bb=new RecentDocument();
DataSet ff=bb.getRecentDocument("Name='aa'");
dataGrid1.DataSource = ff;
dataGrid1.DataMember = ff.Tables[0].TableName;
}在Button3的单击事件调用那个方法,可是显示的只有字段,没有记录,这个表里是有记录的,请大家指点!
这句错了吧
应该是
cmd.CommandText="select * from RecentDocument where 字段名="+wherestring;
DataSet ff=bb.getRecentDocument("Name='aa'");
public DataSet getRecentNdocument(int N,string wherestring)
你也没绑定啊!DataGrid1.DataBind();
dataGrid1.DataMember = ff.Tables[0].TableName;//你没有写这一句!!!
dataGrid1.DataBind();
在哪里写?
dataGrid1.DataMember = ff.Tables[0].TableName;
这句后面
加完就出这个错误了
应该是“System.Web.UI.WebControls.DataGrid”啊。