public queue getQueueDataByID(int queueID)
{
string DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
SqlDataAdapter da;
DataSet ds = new DataSet();
queue myQueue = new queue();
StringBuilder sqlCommand = new StringBuilder();
sqlCommand.AppendLine("Select * from QueueTable where");
sqlCommand.AppendLine("id = @paraId");
try
{
SqlConnection myConn = new SqlConnection(DBConnect);
// sqlCommand.Parameters.AddWithValue("paraCustId", tbCustId.Text);
da = new SqlDataAdapter(sqlCommand.ToString(), myConn);
da.SelectCommand.Parameters.AddWithValue("paraId", queueID);
// fill dataset
da.Fill(ds, "QueueTable");
//conn.Close();
int rec_cnt = ds.Tables["QueueTable"].Rows.Count;
DataRow row = ds.Tables["QueueTable"].Rows[rec_cnt-1 ];
myQueue.queueNo = row["QueueNo"].ToString();
myQueue.NRIC = row["NRIC"].ToString();
myQueue.ContactNo = row["ContactNo"].ToString();
}
catch (SqlException ex)
{
}
return myQueue;
}
這是我的課最後一行中獲得價值,我試圖從數據庫中檢索在Web表單中顯示的最後一排的DATAS,任何想法我怎麼能做到這一點?我的「id」,主鍵被設置爲自動增量。從SQL Server數據庫C#
這段代碼拋出異常或不返回最後一排? – jjj
嗨,謝謝你的回覆,主要觀點是,我不知道如何檢索,或者更喜歡,我不知道在我的web表單中使用什麼代碼來檢索。 – ShengisBored
因爲你需要綁定這個隊列到web表單fields.Please參考http://stackoverflow.com/questions/18800566/how-to-bind-data-in-html-table-in-asp-net-web -form – jjj