我的代码有什么问题?当我设置我的SQL和ASP之间的连接时,它给了我这个错误:无法找到sqlcommand。您是否错过......”设置连接时出错
这里是我的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
SqlCommand cmd = new SqlCommand("Insert into CarTab(Brand,Model,Plate,Color,Service) Values (@brand,@model,@plate,@color,@year,@service)",conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@brand", Label1.Text);
cmd.Parameters.AddWithValue("@model", Label2.Text);
cmd.Parameters.AddWithValue("@plate", Label3.Text);
cmd.Parameters.AddWithValue("@color", Label4.Text);
cmd.Parameters.AddWithValue("@year", Label5.Text);
cmd.Parameters.AddWithValue("@service", Label6.Text);
conn.Open();
cmd.ExecuteNonQuery();
}
我已经把使用system.data;和使用system.data.sql;但它仍然是相同的 错误: 1.无法找到类型或名称空间名称'SqlConnection'(缺少使用指令或程序集引用吗?) 2.无法找到类型或名称空间名称'SqlConnection'(是否缺少使用指令或程序集引用?) 3.名称'ConfigurationManager'在当前上下文中不存在 4.类型或名称空间名称'SqlCommand'co (找不到使用指令或程序集引用?) 5.无法找到类型或名称空间名称'SqlCommand'(您是否缺少使用指令或程序集引用?)
Hope这有助于您找到解决我的错误的方法。谢谢
你用'sqlcommand'如在味精somwhere所示的一样呢? – V4Vendetta 2012-07-17 06:36:50
不要忘记你的'使用'块! – 2012-07-17 06:42:43