0

我正在创建和插入表单,我收到了这个错误,这是我在代码隐藏中的代码:

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;
4

1 回答 1

2

后面有一个额外的逗号description

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

于 2013-08-22T22:48:36.067 回答