왜이 잘못된 구문입니다Visual Studio에서 '('
설명 : 처리되지 않은 예외가 현재 웹 요청을 실행하는 동안 발생한 오류와에 대한 자세한 내용은 스택 추적을 검토하십시오. 이 코드에서 유래
예외 정보 :. System.Data.SqlClient.SqlException : 근처의 구문이 잘못되었습니다 '('
소스 오류 :.
Line 43: "VALUES (@0, @1, @2, @3)";
Line 44:
Line 45: db.Execute(sql, title, content, 1, slug); <--------
Line 46: }
Line 47: }
을
이 내 코드입니다 : 여기
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using WebMatrix.Data;
/// <summary>
/// Summary description for PostHandler
/// </summary>
public class PostHandler : IHttpHandler
{
public PostHandler()
{
//
// TODO: Add constructor logic here
//
}
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
var title = context.Request.Form["postTitle"];
var content = context.Request.Form["postContent"];
var slug = CreateSlug(title);
using (var db = Database.Open("DefaultConnection"))
{
var sql = "SELECT * FROM Posts WHERE Slug = @0";
var result = db.QuerySingle(sql, slug);
if (result != null)
{
throw new HttpException(409, "Slug is already in use.");
}
sql = "INSERT INTO Posts (Title, Content, AuthorId, Slug" +
"VALUES (@0, @1, @2, @3)";
db.Execute(sql, title, content, 1, slug);
}
}
private static string CreateSlug(string title)
{
title = title.ToLowerInvariant().Replace(" ", "-");
title = Regex.Replace(title, @"[^0-9a-z-]", string.Empty);
return title;
}
}
의 내 데이터베이스, 나는 마이크로 소프트 SQL Server Management Studio를 사용하고 있습니다처럼 보이는 방법!
이[1] http://i.imgur.com/2xWJEKR.jpg
코드가 더 필요합니다. 그것은 당신의 오류가 페이지의 위로 나아갈 수 있습니다. – user1269942
sql – Parker
의 값은 무엇입니까? SQL 문에 오류가 있습니다. 여기 출력 할 수 있니? – trnelson