System.Data.SqlClient.SqlException (0x80131904): 必须声明标量变量

.net事件代码protectedvoidButton1_Click(objectsender,EventArgse){{if(Session["uname"]==nul... .net 事件代码
protected void Button1_Click(object sender, EventArgs e)
{
{
if (Session["uname"] == null)
{
Label17.Text = "请先登陆!";
}
else
{
Label18.Text ="我选中了"+txtDate.Text+" "+DropDownList3.Text+" "+"场地"+DropDownList1.Text;
try
{
string str = ConfigurationManager.ConnectionStrings["SufeelConnectionString"].ToString();
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand cmd = new SqlCommand();
string strsql = "select * from [order] where [cid] =@c and [date] = @d and [start_time] = @t";
cmd.CommandText = strsql;
cmd.Connection = con;
cmd.Parameters.Add("@c",SqlDbType.NVarChar).Value= DropDownList1.SelectedValue.ToString();
cmd.Parameters.Add("@d",SqlDbType.Date).Value = DateTime.Parse(txtDate.Text).Date;
cmd.Parameters.Add("@t",SqlDbType.NVarChar).Value= DropDownList3.SelectedValue.ToString();
SqlDataAdapter da = new SqlDataAdapter(strsql, con);
DataSet ds = new DataSet();
int count = da.Fill(ds, "order");
if (count > 0)
{
Label17.Text = "该场地已经预约";
}
else
{ strsql = "INSERT INTO [order] (uname,cid,date,start_time,paid) VALUES('"+Session["uname"]+"',@c,@d,@t,N)";
cmd.ExecuteNonQuery();
Label17.Text = "已成功预约请尽快付款。";
}

}
catch (Exception ee)
{
Label8.Text = ee.ToString();
}

}

}
}
展开
 我来答
whm412
2013-03-06 · TA获得超过515个赞
知道小有建树答主
回答量:289
采纳率:66%
帮助的人:275万
展开全部
strsql = "INSERT INTO [order] (uname,cid,date,start_time,paid) VALUES('"+Session["uname"]+"',@c,@d,@t,N)";
cmd.CommandText = strsql; //加入这行代码,因为字符串是特殊的引用类型,值改变后,就是另一个对象了。

cmd.ExecuteNonQuery();
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式