我有搜索代码,但是在调试后显示{显示错误的错误{the','附近的语法. [英] i have search code but ther is error popping after debugging about an error showing{ Incorrect syntax near ','.}
本文介绍了我有搜索代码,但是在调试后显示{显示错误的错误{the','附近的语法.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
///我正在尝试提供数据输出,该数据表明如果用户输入名称,则选择日期到他想要的日期,输出必须显示来自所选日期的名称记录,这是她的代码
//i am trying to give an output of data showing that if a user enters a name selects the date to his desired date output must be showing name records from date selected her is my code
private void button5_Click(object sender, EventArgs e)
{
con = new SqlConnection(@"Data Source=abbas-PC\SQLEXPRESS;Initial Catalog=EREGISTRY;Integrated Security=True");
ds = new DataSet();
cmd = new SqlCommand("select * from REGISTRY where CUSTUMER=@CUSTUMER,DATE=@DATE",con);
cmd.Parameters.Add("CUSTUMER", SqlDbType.NVarChar, 40).Value = textBox6.Text;
//cmd = new SqlCommand("select * from REGISTRY where DATE=@DATE", con);
cmd.Parameters.Add("DATE", SqlDbType.NVarChar, 20).Value = dateTimePicker2.Value;
da = new SqlDataAdapter(cmd);
con.Open();
da.Fill(ds, "reg");
con.Close();
dataGridView1.DataSource = ds.Tables[0];
推荐答案
可以" t写"CUSTUMER = @ CUSTUMER,DATE = @ DATE".
您应该输入"CUSTUMER = @ CUSTUMER AND DATE = @ DATE"
另一件事是,您应将日期视为日期.不能将其转换为字符串.
You can''t write "CUSTUMER=@CUSTUMER,DATE=@DATE".
You should write "CUSTUMER=@CUSTUMER AND DATE=@DATE"
Another thing as that you should treat dates as Date. Not convert it to strings.
private void button5_Click(object sender, EventArgs e)
{
con = new SqlConnection(@"Data Source=abbas-PC\SQLEXPRESS;Initial Catalog=EREGISTRY;Integrated Security=True");
ds = new DataSet();
cmd = new SqlCommand("select * from REGISTRY where CUSTUMER=@CUSTUMER and DATE=@DATE",con);
cmd.Parameters.Add("CUSTUMER", SqlDbType.NVarChar, 40).Value = textBox6.Text;
//cmd = new SqlCommand("select * from REGISTRY where DATE=@DATE", con);
cmd.Parameters.Add("DATE", SqlDbType.NVarChar, 20).Value = dateTimePicker2.Value;
da = new SqlDataAdapter(cmd);
con.Open();
da.Fill(ds, "reg");
con.Close();
dataGridView1.DataSource = ds.Tables[0];
更正查询中的这一行
correct this line in query
cmd = new SqlCommand("select * from REGISTRY where CUSTUMER=@CUSTUMER,DATE=@DATE",con);
到
to
cmd = new SqlCommand("select * from REGISTRY where CUSTUMER=@CUSTUMER and DATE=@DATE",con);
代替,使用和
in place of , use and
这篇关于我有搜索代码,但是在调试后显示{显示错误的错误{the','附近的语法.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文