我有一个列名称Transaction Id,它被设置为标识规范为Yes ..我的问题是如何在我的数据库中向我的Listview或文本框中显示最后一个Transaction Id?谢谢
答案 0 :(得分:0)
完成所需输出的SQL查询将是:
select top 1 TransactionId
from YourTransTable
order by TransactionId desc
然后只是一些快速的C#代码将TextBox的Text设置为结果:
int LastTransId;
SqlConnection DbConn = new SqlConnection(YourConnString);
SqlCommand ExecSql = new SqlCommand(string.Empty, DbConn);
ExecSql.CommandText = @"
select top 1 TransactionId
from YourTransTable
order by TransactionId desc";
using (DbConn)
{
DbConn.Open();
using (ExecSql)
LastTransId = Convert.ToInt32(ExecSql.ExecuteScalar());
}
YourTextBox.Text = LastTransId.ToString();