gpt4 book ai didi

sql - '/'应用程序中的服务器错误。 ')'附近的语法不正确

转载 作者:行者123 更新时间:2023-12-03 08:23:27 26 4
gpt4 key购买 nike

我正在创建并插入表单,但出现此错误,这是我在代码隐藏中的代码:

protected void btnSave_Click(object sender, EventArgs e)
{
string Selected = category_ddl.SelectedValue;
lb_date.Text = System.DateTime.Now.ToLongDateString();
process();
}

private void process()
{
string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename= |DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True";
string sql = "INSERT INTO News (date_time,title,author,source,category,description,) VALUES (@date, @title, @author,@source,@Selected,@description)";
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@date", lb_date.Text.ToString());
cmd.Parameters.AddWithValue("@title", title_tb.Text.ToString());
cmd.Parameters.AddWithValue("@author", author_tb.Text.ToString());
cmd.Parameters.AddWithValue("@source", source_tb.Text.ToString());
cmd.Parameters.AddWithValue("@Selected", category_ddl.Text.ToString());
cmd.Parameters.AddWithValue("@description", desc_tb.Text.ToString());
cmd.ExecuteNonQuery();
conn.Close();
}

这是我的错误:
Server Error in '/' Application.

Incorrect syntax near ')'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near ')'.

Source Error:


Line 37: cmd.Parameters.AddWithValue("@Selected", category_ddl.Text.ToString());
Line 38: cmd.Parameters.AddWithValue("@description", desc_tb.Text.ToString());
Line 39: cmd.ExecuteNonQuery();
Line 40: conn.Close();
Line 41: }

第39行:cmd.ExecuteNonQuery();以红色突出显示。我做错了什么?,我使用此方法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

最佳答案

您在description之后再加上一个逗号:

string sql = "INSERT INTO News (date_time,title,author,source,category,description,)

关于sql - '/'应用程序中的服务器错误。 ')'附近的语法不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18391975/

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