Home > Database > Mysql Tutorial > Incorrect syntax near the keyword 'user'错误的解决方法

Incorrect syntax near the keyword 'user'错误的解决方法

WBOY
Release: 2016-06-07 17:51:51
Original
3130 people have browsed it

本文章来介绍一下关于Incorrect syntax near the keyword user错误的解决方法,有需碰到此类问题的朋友可以参考一下下。

事情是这样子的,公司一个很要好的同事因为他先前学JAVA的,可能最近项目上需求需要学习.NET,所以就遇到取的问题,刚开始想这多简单啊!~,然后他就创建了一个表,user,有3个字段,id,username和pass。

远程连接到他的电脑,开始操作。

如下:

然后,帮他写了一个里面取username和password的sql语句:

string connStr = @"Data Source=.SQLEXPRESS;AttachDbFilename=C:DesktopProjectTest练习项目集中营HahaWebApplication1App_DataDatabase1.mdf;Integrated Security=True;User Instance=True";
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "Select * from user where id='" + 1 + "'";//这里需要注意,我用了 user 这个表名 悲剧从这里开始。。
                    cmd.Connection = conn;
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        string user = Convert.ToString(reader["username"]);
                        string pass = Convert.ToString(reader["password"]);
                    }
                }
            }

然后,点确定,很开心的等啊等。。

等到一个错误!~

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template