数据库查询错误 [英] error in database query
本文介绍了数据库查询错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我的数据库查询命令中有错误
当我运行程序时,错误消息如下:
incorrect syntax near the keyword "WHERE
这是代码
hello
I have an error in my database command of query
when I run the program , an error appear on message as follow
incorrect syntax near the keyword "WHERE
this is the code
public static Boolean AddTodo(string name, string email, string password)
{
Boolean c = false;
try
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Documents\WinDB.mdf;Connect Timeout=30;User Instance=True;Integrated Security=SSPI";
connection.Open();
SqlCommand command1 = new SqlCommand("SELECT * FROM UserInfo. WHERE UserName= @UserName", connection);
command1.Parameters.Add(new SqlParameter("@UserName", name));
command1.ExecuteNonQuery();
SqlDataReader reader = command1.ExecuteReader();
{
if (!reader.HasRows)
{
reader.Close();
SqlCommand command = new SqlCommand("insert into UserInfo. (UserName, UserEmail, Password) values (@UserName, @UserEmail, @Password)", connection);
command.Parameters.Add(new SqlParameter("@UserName", name));
command.Parameters.Add(new SqlParameter("@UserEmail", email));
command.Parameters.Add(new SqlParameter("@Password", password));
command.ExecuteNonQuery();
c = true;
}
else
{
MessageBox.Show("UserName is thaken");
}
}
connection.Close();
}
catch (SqlException e)
{
MessageBox.Show(e.Message);
}
return c ;
}
为什么会出现错误?
有什么问题! :(
谢谢
PS:UserName密钥世界与数据库中一样
即同名
why is there error ?
what is the wrong !! :(
thanks
PS: UserName key world is as in the database
i.e the same name
推荐答案
您似乎在表名后面有一个额外的点.试试:
You seem to have an extra dot after the table name. Try:
SqlCommand command1 = new SqlCommand("SELECT * FROM UserInfo WHERE UserName= @UserName", connection);
请注意,这同样适用于您的INSERT语句
Note that the same applies to your INSERT statement
表名旁边的这个点
whats this dot next your table name
new SqlCommand("SELECT * FROM UserInfo.
您的代码:
your code :
SqlCommand command1 = new SqlCommand("SELECT * FROM UserInfo. WHERE UserName= @UserName", connection);
试试这个
try this
SqlCommand command1 = new SqlCommand("SELECT * FROM UserInfo WHERE UserName= @UserName", connection);
我希望这项工作:)
i hope this work :)
这篇关于数据库查询错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文