希望這是一個簡單的超出範圍的數據集例外
我正在從我的數據集的一列中提取數據。由於提供了SQL查詢,一個ID只會返回一個結果。所以我會認爲這個結果總是在數據集的'0'行。
如果我點擊我的datagrid中的第一個結果........發送ID'0'到我的第二頁,然後從數據庫中提取圖像名稱它崩潰。如果我在網格中選擇第二個結果(即'1'),那很好。
這裏是我的代碼:
SqlConnection sqlcon = new SqlConnection(connstring);
SqlCommand sqlcmd = new SqlCommand("select pic from cds WHERE _id = '" + passedID + "'", sqlcon);
SqlDataAdapter adp = new SqlDataAdapter(sqlcmd);
DataSet ds = new DataSet();
adp.Fill(ds);
// Rows set to '0' for the first result in the dataset but crashes if the first item is selected.
object a = ds.Tables[0].Rows[0]["pic"];
string test = a.ToString();