求助:未处理的“System.IndexOutOfRangeException”异常,无法找到表 0
try{
OleDbConnection con=new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Application .StartupPath +"\\MyHotel.mdb");
con.Open ();
string str="insert into HotelRoom values ('"+textBox1 .Text +"','"+textBox2 .Text +"','"+textBox3 .Text +"','"+textBox4 .Text+"')";
string sql2="Select * from HotelRoom";
OleDbCommand comm=new OleDbCommand (sql2,con);
OleDbDataAdapter adapter=new OleDbDataAdapter (str,con);
adapter .InsertCommand =comm ;
DataSet setobj=new DataSet ();
adapter.Fill (setobj,"HotelRoom");
DataTable table=setobj.Tables[0];
DataRow row=table .NewRow ();
row["biaoshi"]=textBox1 .Text;
row["xueli"]=textBox2 .Text ;
row["Name"]=textBox3 .Text ;
row["Date"]=textBox4 .Text ;
table.Rows .Add (row);
adapter .Update (setobj ,"HotelRoom");
setobj .AcceptChanges ();
MessageBox .Show ("保存成功");
}
catch(OleDbException ex)
{
MessageBox .Show (ex.Message .ToString ());
}
上述代码运行后,输入数据按保存按钮保存时发生异常:无法找到表 0.什么原因啊?
数据却可以正常保存. 怎么纠正这个错误呢?
[[it] 本帖最后由 tingren2525 于 2008-3-24 20:49 编辑 [/it]]