2013-08-22 30 views
0

林創建和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; 

回答

2

description之後有一個額外的逗號:

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

+0

男孩哦!那小小的逗號吹我T.T 我認爲,我應該穿glassess,謝謝你! –

相關問題