Problemer med Insert via Web service
Hej Eksperterjeg er igang med at lave en winform, hvor jeg skal indsætte records i en msSql via en webservice. Jeg kan godt hente ud via web service, men når jeg prøver at insætte records opstår følgende fejl:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: Incorrect syntax near '?'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at tourDAL.DAL.insertCustomer(String FirstName, String LastName, String Organization, String Address, Int32 ZipCode, String City, String Email, String Password) in \DAL.cs:line 93
at tourBLL.BLL.insertCustomer(String FirstName, String LastName, String Organization, String Address, Int32 ZipCode, String City, String Email, String Password) in \BLL.cs:line 42
at Service.insertCustomer(String FirstName, String LastName, String Organization, String Address, Int32 ZipCode, String City, String Email, String Password) in \Service.cs:line 39
--- End of inner exception stack trace ---
Min DAL ser sådan ud:
public void insertCustomer(string FirstName, string LastName, string Organization, string Address, int ZipCode, string City, string Email, string Password)
{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.CommandText = "INSERT INTO customer (firstName, lastName, organization, address, zipCode, city, email, [password]) VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = FirstName;
cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = LastName;
cmd.Parameters.Add("@Organisation", SqlDbType.VarChar).Value = Organization;
cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = Address;
cmd.Parameters.Add("@ZipCode", SqlDbType.Int).Value = ZipCode;
cmd.Parameters.Add("@City", SqlDbType.VarChar).Value = City;
cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = Email;
cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = Password;
cmd.ExecuteNonQuery();
if (conn.State != ConnectionState.Closed)
conn.Close();
}
Håber i kan hjælpe mig.