我使用在其表的簡歷和列的PageIndex數據庫,類型是數據庫數字,不過,我想這PageIndex的值存儲爲一個整數,我得到異常錯誤容納張數
指定的轉換無效。
這裏是代碼
string sql;
string conString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=D:\\Deliverable4.accdb";
protected OleDbConnection rMSConnection;
protected OleDbDataAdapter rMSDataAdapter;
protected DataSet dataSet;
protected DataTable dataTable;
protected DataRow dataRow;
上按鈕點擊
sql = "select PageIndex from RESUME";
rMSConnection = new OleDbConnection(conString);
rMSDataAdapter = new OleDbDataAdapter(sql, rMSConnection);
dataSet = new DataSet("pInDex");
rMSDataAdapter.Fill(dataSet, "RESUME");
dataTable = dataSet.Tables["RESUME"];
INT p食指= (INT)dataTable.Rows [0] [0];
rMSConnection.Close();
if (pIndex == 0)
{
Response.Redirect("Create Resume-1.aspx");
}
else if (pIndex == 1)
{
Response.Redirect("Create Resume-2.aspx");
}
else if (pIndex == 2)
{
Response.Redirect("Create Resume-3.aspx");
}
}
我得到這一行
int pIndex = (int)dataTable.Rows[0][0];
空數據庫值會產生'DBNull.Value',不'null'。 – 2010-06-14 18:35:33
* @ Adam Robinson:*正確(我加了這個例子),但是請注意,如果*不是第一行的第一列,那麼仍然可以發生'null',即。當返回的結果集完全爲空時。 – stakx 2010-06-14 18:36:32