目前正在开发 ASP.NET Web 应用程序,并开始意识到我正在一遍又一遍地编写相同的 Boiler Plate 代码..
即
SqlDataReader myReader = null;
SqlCommand SQLcmd = new SqlCommand();
SqlConnection SQLConn = new SqlConnection();
String SQLStatement = "Select this 'nd That";
SQLConn.ConnectionString = SQLConnectionString;
SQLConn.Open();
SQLcmd.Connection = SQLConn;
SQLcmd.CommandText = SQLStatement;
myReader = SQLcmd.ExecuteReader();
while (myReader.Read())
{
//Do some awesome
}
SQLConn.Close();
}
.NET 世界现在如何使用 SQL?
基本上我怎么能不花半天时间复制和粘贴该代码呢?
每个人都在使用 Linq to SQL 吗?如果是这样,请给我指一个教程!
非常感谢!
丹尼尔
最佳答案
关于ASP.NET 4 SQL 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3934446/