gpt4 book ai didi

asp.net - 拒绝执行 ExecuteNonQuery : Incorrect syntax near '('

转载 作者:搜寻专家 更新时间:2023-10-30 21:38:40 24 4
gpt4 key购买 nike

我正在尝试将数据插入我的数据库,但出现错误:

Incorrect syntax near '('.

这是我的代码:

string username = Session["Session"].ToString();

con = new SqlConnection("Data Source=MICROSOF-58B8A5\\SQL_SERVER_R2;Initial Catalog=Daniel;Integrated Security=True");
con.Open();

string knowWhichOne = "SELECT ID FROM Users WHERE Username='" + UserOrGuest.Text + "'";

SqlCommand comm = new SqlCommand(knowWhichOne, con);
int userID = (Int32)comm.ExecuteScalar();

knowWhichOne = "SELECT ClassID FROM Users WHERE Username='" + UserOrGuest.Text + "'";

comm = new SqlCommand(knowWhichOne, con);
int classID = (Int32)comm.ExecuteScalar();

knowWhichOne = "SELECT SchoolID FROM Users WHERE Username='"+UserOrGuest.Text + "'";

comm = new SqlCommand(knowWhichOne, con);
int schoolID = (Int32)comm.ExecuteScalar();

if (RadioWords.Checked == true)
{
game = 1;
}
else
{
game = 2;
}


string sqlqueryString = "INSERT INTO (GameID, UserID, LengthOfArray, NumberOfErrors, ClassID, SchoolID) VALUES (@GameID, @UserID, @LengthOfArray, @NumberOfErrors, @ClassID, @SchoolID)";

SqlCommand commandquery = new SqlCommand(sqlqueryString, con);

commandquery.Parameters.AddWithValue("GameID", game);
commandquery.Parameters.AddWithValue("UserID", userID);
commandquery.Parameters.AddWithValue("LengthOfArray", HowMany.Text);
commandquery.Parameters.AddWithValue("NumberOfErrors", 0);
commandquery.Parameters.AddWithValue("ClassID", classID);
commandquery.Parameters.AddWithValue("SchoolID", schoolID);

commandquery.ExecuteNonQuery();
con.Close();

我在 Debug模式下运行它,它接受一切直到“ExecuteNonQuery();”行。

有人知道我做错了什么吗?

谢谢!

最佳答案

你这样做了:

INSERT INTO (GameID....

但应该这样做:

INSERT INTO tablename (GameID....

关于asp.net - 拒绝执行 ExecuteNonQuery : Incorrect syntax near '(' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8715729/

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