datagrid显示错误?
fn123 2003-11-28 09:45:59 IErrorInfo.GetDescription 因 E_FAIL(0x80004005) 而失败。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.OleDb.OleDbException: IErrorInfo.GetDescription 因 E_FAIL(0x80004005) 而失败。
源错误:
行 34: DataSet ds=new DataSet();
行 35: OleDbDataAdapter da=new OleDbDataAdapter(str,cn);
行 36: da.Fill(ds,"content1");
行 37: grid.DataSource=ds.Tables["content1"].DefaultView;
行 38: grid.DataBind();
代码如下:
public void bindgrid(DataGrid grid,string str)
{
OleDbConnection cn=new OleDbConnection();
cn.ConnectionString="Provider=Microsoft.JET.OleDb.4.0;Data Source="+System.Web.HttpContext.Current.Server.MapPath(appsettings("dbpath1"))+";User Id="+appsettings("userid")+";Password="+appsettings("password")+";";
OleDbCommand cm=new OleDbCommand();
cm.Connection=cn;
cm.CommandText=str;
cn.Open();
DataSet ds=new DataSet();
OleDbDataAdapter da=new OleDbDataAdapter(str,cn);
da.Fill(ds,"content1");
grid.DataSource=ds.Tables["content1"].DefaultView;
grid.DataBind();
cn.Close();
cm.Dispose();
cn.Dispose();
ds.Dispose();
}
调用:
private void Button1_Click(object sender, System.EventArgs e)
{
look lo=new look();
lo.bindgrid(grid,"SELECT ticket.id as id,station_1.stationname as start,station.stationname as get,train.trainnum as trainnum,ticket.starttime as starttime,ticket.gettime as gettime,ticket.price as price,ticketstype.typename as type,ticket.able as able FROM ticketstype INNER JOIN (train INNER JOIN ((station INNER JOIN ticket ON station.id = ticket.getid) INNER JOIN station AS station_1 ON ticket.startid = station_1.id) ON train.id = ticket.trainnumid) ON ticketstype.id = ticket.typeid;");
}
sql语句可以在access中运行.