本帖最后由 彭家贰小姐 于 2013-8-9 10:28 编辑
第一个报错:
SqlCommand commd = new SqlCommand() 修改为: SqlCommand commd = sqlconn.CreateCommand()
第二个报错:
添加sqlconn.Open();[不是很清楚楼主using时不open是怎么实现的?希望楼主分享代码]
第三个报错:
delete * from T_Mark 修改为: delete from T_Mark不能加*
最终代码- private void btnConnect_Click(object sender, RoutedEventArgs e)
- {
- string connstr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;
- using (SqlConnection sqlconn = new SqlConnection(connstr))
- {
- sqlconn.Open();
- using (SqlCommand commd = sqlconn.CreateCommand())
- {
- commd.CommandText = "delete from T_Mark";
- commd.ExecuteNonQuery();
- }
- }
- }
复制代码 |