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