我有一个乐透抽奖方法,它应该从购买的彩票数据库中找到中奖彩票。但我无法显示查询结果。(我知道这不是乐透的真正运作方式,我稍后会随机化数字:P)
绘制.aspx.cs
public void LottoDraw(object sender, EventArgs e)
{
var connectionstring = "Server=C;Database=lotto;User Id=lottoadmin;Password=password;";
using (var con = new SqlConnection(connectionstring)) // Create connection with automatic disposal
{
con.Open();
using (var tran = con.BeginTransaction()) // Open a transaction
{
// Create command with parameters
string sql =
"SELECT TOP 1 * FROM tblLotto ORDER BY NEWID()";
var cmd = new SqlCommand(sql, con);
cmd.Transaction = tran;
cmd.ExecuteNonQuery(); // Execute the query
tran.Commit(); // commit transaction
Response.Write("<br />");
Response.Write("<br />");
Response.Write("end...");
}
}
}