现在很多都简写了
using(SqlConnection sql = new SqlConnection(conStr))
{
......
SqlCommand cmd = new SqlCommand(sql,con);
......
}
以前是用的try...catch...finally,代码虽然多些,好处是可以错误处理。如果catch到错误就return 0;
现在用using了,要错误处理,比如插入return cmd.ExecuteNonQuery();如果返回1表示插入成功,如果返回0表示插入失败;
其实这个0表示插入失败在using中是不起作用的,如果sql语句执行出错了,是不会得到0的。。。
请问哈你们是怎么使用的呢?难道还是不用using么???