gpt4 book ai didi

c# - SQL错误关键字 'user'附近的语法不正确

转载 作者:行者123 更新时间:2023-11-30 19:37:30 24 4
gpt4 key购买 nike

<分区>

我正在尝试将 SQL Server 2008 连接到 c# windows 应用程序。
它给我一个错误。

try
{
con = new SqlConnection("server=sameer-PC;database=Demo;Integrated Security=true;UID=admin;password=admin");
//String query = "select * from user";

con.Open();
cmd = new SqlCommand("select * from user", con);

Console.WriteLine("connection open{0}");

SqlDataReader myReader = null;

myReader = cmd.ExecuteReader();
while (myReader.Read())
{
Console.Write((myReader["name"]));
}
con.Close();
}

错误:

类型的第一次机会异常

'System.Data.SqlClient.SqlException' occurred in System.Data.dll
System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'user'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReadeThe thread 'vshost.RunParkingWindow' (0x820) has exited with code 0 (0x0).
The thread '<No Name>' (0xc80) has exited with code 0 (0x0).

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com