フォームを作成して INSERT すると、このエラーが発生しました。これはコードビハインドのコードです。
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;