【发布时间】:2014-01-02 05:01:52
【问题描述】:
我正在尝试从数据库中获取用户的详细信息以显示在某些文本框中;但是我的代码似乎有问题。不断出现以下错误:
查询表达式中的语法错误(逗号)
这是完整的代码:
string filePath;
try
{
filePath = (Application.StartupPath + ("\\" + DBFile));
connection = new System.Data.OleDb.OleDbConnection((ConnectionString + filePath));
connection.Open();
System.Data.OleDb.OleDbDataReader reader;
System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand();
command.Connection = connection;
// ---retrieve user's particulars---
command.CommandText = ("SELECT * FROM Enroll WHERE ID=" + textBox1);
reader = command.ExecuteReader(CommandBehavior.CloseConnection);
reader.Read();
// ---display user's particulars---
textBox2.Text = reader["SSN"].ToString();
textBox3.Text = reader["FirstName"].ToString();
textBox4.Text = reader["LastName"].ToString();
}
【问题讨论】: