要清除Windows应用程序中'='附近的错误语法错误 [英] To clear a error incorrect syntax near '=' in windows application

查看:63
本文介绍了要清除Windows应用程序中'='附近的错误语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在给定编码中,由于在="="附近语法错误,我有错误.请更正该错误

i have error as incorrect syntax near ''='' , in given coding. please correct that error

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
       {

           cmd = new SqlCommand(" select * from imagedemo where='"+listBox1.SelectedItem.ToString()+"'", con);
           con.Open();
           SqlDataReader dr;
           try
           {
               dr = cmd.ExecuteReader();
               if (dr.Read())
               {
                   byte[] picture = (byte[])dr["imgimage"];
                   ms = new MemoryStream(picture);
                   ms.Seek(0, SeekOrigin.Begin);
                   pictureBox1.Image = Image.FromStream(ms);

               }

           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
           finally
           {
               con.Close();
           }
       }

推荐答案

查询select * from imagedemo where=''"+listBox1.SelectedItem.ToString()+"''"存在问题.
您尚未提供列名.

尝试直接在SQL后端编辑器中运行此查询,以查看语法是否正确.
There is an issue with the query select * from imagedemo where=''"+listBox1.SelectedItem.ToString()+"''".
You have not provided the column name.

Try running this query in the SQL backend editor directly to see if the syntax is all correct.


您的SQL查询未声明您要查询的字段.而不是 WHERE = ,您应该有WHERE yourField =(其中,您的字段应替换您要查询的字段的名称.您还应该考虑使用参数化查询而不是字符串连接,因此我将这样编写查询: :-

Your SQL query does not state the field that you are querying against. Instead of WHERE = , you should have WHERE yourField = (where yourField should be substituted for the name af the field you wish to query against. You should also consider using parameterised queries instead of string concatenation, so I would write the query like this:-

SELECT field1, field2, field3 FROM myTable WHERE field4 = @field4Parameter;<br />
mycommand.Parameters.AddWithValue("@field4Parameter", myParameter)



注意,我为查询中的所有字段命名,而不是使用*符号.这样,当我检索结果时,它们总是以相同的顺序返回.

希望对您有帮助



Notice i named all my fields in the query instead of using the * symbol. That way when I retrieve the results they always come back in the same order.

Hope that helps


您在where子句中缺少参数,必须在where和before之后指定字段名称=
You are missing parameter in where clause,must specify field name after where and before =


这篇关于要清除Windows应用程序中'='附近的错误语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆