Ich erhalte diesen SyntaxfehlerSystem.Data.SqlClient.SqlException: falsche Syntax in der Nähe '('
System.Data.SqlClient.SqlException. Falsche Syntax in der Nähe '('“
auf der
cmd.ExecuteNonQuery();
Codezeile in meiner Klasse-Datei.
ich habe versucht, rewritin g die ganze Klassendatei und meine Knopfklickmethode, aber irgendwie mache ich es immer noch falsch.
Hier ist mein Code
customer.cs:
//properties
public int memberId { get; set; }
public string name { get; set; }
public string salutation { get; set; }
public string telNo { get; set; }
public string eMailAddr { get; set; }
public string password { get; set; }
public DateTime birthDate { get; set; }
public string city { get; set; }
public string country { get; set; }
public int add()
{
string strConn = ConfigurationManager.ConnectionStrings["NPCSConnectionString"].ToString();
SqlConnection conn = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand("INSERT INTO Member (Name, Salutation, TelNo, EmailAddr, Password, BirthDate, City, Country"
+ "VALUES(@memberID, @name, @salutation, @telNo, @eMailAddr, @password, @birthDate, @city, @country)", conn);
cmd.Parameters.AddWithValue("@memberID", memberId);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@salutation", salutation);
cmd.Parameters.AddWithValue("@telNo", telNo);
cmd.Parameters.AddWithValue("@eMailAddr", eMailAddr);
cmd.Parameters.AddWithValue("@password", password);
cmd.Parameters.AddWithValue("@birthDate", birthDate);
cmd.Parameters.AddWithValue("@city", city);
cmd.Parameters.AddWithValue("@country", country);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
return 0;
}
Der folgende Code wird verwendet,
Customer objCustomer = new Customer();
objCustomer.memberId = 8;
objCustomer.name = txtName.Text;
objCustomer.salutation = ddlSalutation.SelectedItem.Value;
objCustomer.telNo = txtTelNo.Text;
objCustomer.eMailAddr = txtEmail.Text;
objCustomer.password = txtPassword.Text;
objCustomer.birthDate = calBirthdate.SelectedDate;
objCustomer.city = txtCity.Text;
objCustomer.country = ddlCountry.SelectedItem.Value;
int errorCode = objCustomer.add();
if (errorCode == 0)
{
Response.Redirect("SuRegister.aspx");
}
Sie fehlen ein ')' in Ihrer SQL-Abfrage. – mstaessen
Sie schließen ')' hier: 'INSERT INTO Mitglied (Name, ..., Stadt, Land') – Andrei