2012-12-17 103 views
2

我在asp.net Npgsql.NpgsqlException:錯誤:42601:在語法錯誤或接近 「其中」

//setup profile 
    [WebMethod] 
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
    public void SetProfile(string userName, string firstName, string lastName, string imageUrl) 
    { 
     //create and open connection 
     NpgsqlConnection profileConnection = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["PrevueConnString"].ToString()); 
     profileConnection.Open(); 

     //create query and command 
     string query = "INSERT into \"Users\" (\"FirstName\", \"LastName\", \"ImageUrl\") values(:fname, :lname, :imageUrl) where \"UserName\" = :user"; 
     NpgsqlCommand profileCommand = new NpgsqlCommand(query, profileConnection); 

     profileCommand.Parameters.Add(new NpgsqlParameter("user", DbType.String)); 
     profileCommand.Parameters.Add(new NpgsqlParameter("fname", DbType.String)); 
     profileCommand.Parameters.Add(new NpgsqlParameter("lname", DbType.String)); 
     profileCommand.Parameters.Add(new NpgsqlParameter("imageUrl", DbType.String)); 

     profileCommand.Parameters[0].Value = userName; 
     profileCommand.Parameters[1].Value = firstName; 
     profileCommand.Parameters[2].Value = lastName; 
     profileCommand.Parameters[3].Value = imageUrl; 

     int result = profileCommand.ExecuteNonQuery(); 

     profileCommand.Dispose(); 
     profileConnection.Close(); 

     string json = new JavaScriptSerializer().Serialize(result); 
     Context.Response.Clear(); 
     Context.Response.ContentType = "application/json"; 
     Context.Response.Flush(); 
     Context.Response.Write(json); 
    } 

的followinf Web服務上調用Web服務,我得到以下錯誤:

Npgsql.NpgsqlException:錯誤:42601:達到或接近"語法錯誤的位置"

+0

請顯示由nPgSQL生成併發送到數據庫的最終SQL。你可以從PostgreSQL服務器日誌中得到這個。你可能需要設置'log_statement ='all''。 –

+0

嘿克雷格,我想我找出了錯誤,我用插入命令'Where'子句,改變了更新,現在事情變得順利...... :)欣賞你的幫助..! – Neville

+0

哇......我很尷尬,我沒有發現。抱歉。 –

回答

2

我想我想通了錯誤,我用了「去哪兒」條款與Insert命令,改變了更新和現在情況平穩... :) 感謝你的幫助..!!

相關問題