请帮我把以下方法转成linq 的方法 谢谢啊。。asp.net的
public static string ReadIdDate()
{
StringBuilder texts = new StringBuilder();
string sql = "select top 1 id from BusinessWaybill order by id desc";
string source = "Data Source=1.1.1.1;Initial Catalog=testDB;Persist Security Info=True;User ID=sa;Password=***";
using (SqlConnection conn = new SqlConnection(source))
{
SqlCommand com = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader r = com.ExecuteReader();
try
{
while (r.Read())
{
texts.Append(r.GetInt32(0).ToString());
}
}
finally
{
r.Close();
}
}
return texts.ToString();
}
------解决方案--------------------
DataClasses1DataContext db = new DataClasses1DataContext();
var s = (from p in db.BusinessWaybill orderby p.id descending
select p.id).First();
texts.Append(s..ToString());
不知道对不对