C# 数据访问报错“SqlCommand”不包含“CommandType”的定义
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSys...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;
public partial class SqlCommand : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void butExecute_Click(object sender, EventArgs e)
{
string connectionStr=WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connectionStr))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText=”“;
//省略
}
}
}
完全照着书上打的,
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText=”“;这三行总是提示
错误 2 “SqlCommand”不包含“CommandType”的定义,并且找不到可接受类型为“SqlCommand”的第一个参数的扩展方法“CommandType”(是否缺少 using 指令或程序集引用?) E:\web网站\WebSitetest\SqlCommand.aspx.cs 25 17 WebSitetest
cmd.Connection,cmd.CommandText也会提示同样的错误 cmd.弹出的提示框没有这几个选项 展开
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;
public partial class SqlCommand : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void butExecute_Click(object sender, EventArgs e)
{
string connectionStr=WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connectionStr))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText=”“;
//省略
}
}
}
完全照着书上打的,
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText=”“;这三行总是提示
错误 2 “SqlCommand”不包含“CommandType”的定义,并且找不到可接受类型为“SqlCommand”的第一个参数的扩展方法“CommandType”(是否缺少 using 指令或程序集引用?) E:\web网站\WebSitetest\SqlCommand.aspx.cs 25 17 WebSitetest
cmd.Connection,cmd.CommandText也会提示同样的错误 cmd.弹出的提示框没有这几个选项 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询