各位专家:
大家好!我是一个新手,才下了“C#Web应用程序入门经典”源代码,并附加了数据库FriendsData数据库。今天编了代码读表User中的数据,总是提示错误“关键字 'user' 附近有语法错误”,于是拿了“C#入门经典”中一个例子,另外的数据运行正常,于是将数据库名、表名和显示的字段名相应的修改,执行到“SqlDataReader thisreader = thiscommand.ExecuteReader();”处仍出现上述错误提示,但别的数据表均能正常按要求显示。用BindingSource绑定时显示正常,不知是什么原因,是不是我的代码有错,请各位高手指教。谢谢!
代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace CAPI_testconnect
{
class Program
{
static void Main(string[] args)
{
SqlConnection thisconnection = new SqlConnection("data source=PRIVATE-CREATOR\\SQL2005;Initial Catalog=FriendsData;User ID=sa;Password=123456");
thisconnection.Open(); SqlCommand thiscommand = thisconnection.CreateCommand(); thiscommand.CommandText = "select * from user"; SqlDataReader thisreader = thiscommand.ExecuteReader();//此处出现错误提示:“关键字 'user' 附近有语法错误”,其他各表都可以按要求正常显示,不知为什么? while (thisreader.Read())
{
Console.WriteLine("\t{0}\t{1}", thisreader["firstname"], thisreader["lastname"]);
} thisreader.Close();
thisconnection.Close(); Console.Write("this program finished ,press Enter /Return to continue");
Console.Read();
}
}
}
大家好!我是一个新手,才下了“C#Web应用程序入门经典”源代码,并附加了数据库FriendsData数据库。今天编了代码读表User中的数据,总是提示错误“关键字 'user' 附近有语法错误”,于是拿了“C#入门经典”中一个例子,另外的数据运行正常,于是将数据库名、表名和显示的字段名相应的修改,执行到“SqlDataReader thisreader = thiscommand.ExecuteReader();”处仍出现上述错误提示,但别的数据表均能正常按要求显示。用BindingSource绑定时显示正常,不知是什么原因,是不是我的代码有错,请各位高手指教。谢谢!
代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace CAPI_testconnect
{
class Program
{
static void Main(string[] args)
{
SqlConnection thisconnection = new SqlConnection("data source=PRIVATE-CREATOR\\SQL2005;Initial Catalog=FriendsData;User ID=sa;Password=123456");
thisconnection.Open(); SqlCommand thiscommand = thisconnection.CreateCommand(); thiscommand.CommandText = "select * from user"; SqlDataReader thisreader = thiscommand.ExecuteReader();//此处出现错误提示:“关键字 'user' 附近有语法错误”,其他各表都可以按要求正常显示,不知为什么? while (thisreader.Read())
{
Console.WriteLine("\t{0}\t{1}", thisreader["firstname"], thisreader["lastname"]);
} thisreader.Close();
thisconnection.Close(); Console.Write("this program finished ,press Enter /Return to continue");
Console.Read();
}
}
}
解决方案 »
- 问大家一个socket异步通信的问题
- Closing 事件过时问题
- URL地址重写问题.在IIS上发布了网站,想从LOGIN开始以后的所有页面都只显示WWW.ABC.COM.怎样做?
- 怎么弹出一个类似qq上线提示那样的tip啊
- 请问一个读文件的问题
- 请问word问题,C#操作word时时报错,Access is denied: 'Interop.Word'
- 怎样使程序运行时动态加载图片到pictureBox中
- Remoting 的两个问题!.NET 的 Remoting 是不是很烂啊?怪毛病很多啊!
- 帮我把这段代码 java 改成 C#
- 为什么我的PANEL高度比winform的高度还高啊
- stream.ReadLine和stream.ReadToEnd有什么不同?
- 手头有个text文本,怎么让visual studio读取并执行其中的内容?
select * from user --看两个的区别
select * from [User]执行Sql语句或者是存储的时候报错 多半是你的Sql语句的问题
user是关键在 加上界定符号
但是 建议在建立表的时候 不要使用关键字 养成好的习惯。。user 换成UesrInfo 什么的