2014-02-16 3 views
-1

내 코드에 문제가 있습니다. Invalid expression term ')' 내가 잘못하고 있는지 확실하지 않습니다. 여기 내 코드가있다.Erorr for 내 Insert 문

protected void btnSubmit_Click(object sender, EventArgs e) 
{ 
    OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = '" + Server.MapPath("WSC_DB.mdb") + "'; Persist Security Info=False"); 

    using (OleDbCommand cmd = new OleDbCommand("insert into Users(UserFirstName, UserLastName, ShipAddress, ShipCity, ShipState, UserPhone, UserEmail, UserName, UserPassword, LoginType) values (@FirstName, @LastName, @Address, @City, @State, @Zip, @Phone, @Email, @Username, @Password, @Logintype)", conn)) 
    { 
     cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text); 
     cmd.Parameters.AddWithValue("@LastName", txtLastName.Text); 
     cmd.Parameters.AddWithValue("@Address", txtAddress.Text); 
     cmd.Parameters.AddWithValue("@City", txtCity.Text); 
     cmd.Parameters.AddWithValue("@State", DropDownList1.SelectedItem.ToString()); 
     cmd.Parameters.AddWithValue("@Zip", txtZip.Text); 
     cmd.Parameters.AddWithValue("@Phone", txtPhone.Text); 
     cmd.Parameters.AddWithValue("@Email", txtEmail.Text); 
     cmd.Parameters.AddWithValue("@Username", txtUsername.Text); 
     cmd.Parameters.AddWithValue("@Password", txtPassword.Text); 
     cmd.Parameters.AddWithValue("@Logintype", "U"); 
     conn.Open(); 
     cmd.ExecuteNonQuery(); 
    } 
} 
+0

는 사용자 및 (UserFirstName? – DarkSquirrel42

+0

@weenoid 무엇? ... – Steve

+0

오류 쇼 사이에 공백을 추가하는 시도가있는 열 목록에 Zip 없다 첫 번째 문에서 OleDbConnection conn = 새 OleDbConnection ("공급자 = Microsoft.Jet.OLEDB.4.0; 데이터 원본 = '"+ Server.MapPath ("WSC_DB.mdb") + "'; 보안 정보 유지 = False"); – user2526337

답변

0

Jet OLEDB를 사용할 때 SQL 문에서 명명 된 매개 변수를 사용할 수 없다는 것을 기억하는 것 같습니다. @FirstName, @LastName, ...을 물음표 '?'로 바꿔야합니다.

오류를 더 잘 분석하려면 전체 오류 메시지와 스택 추적을 포함 시키십시오.

+1

사실 OleDb 매개 변수에는 이름을 지정할 수 있지만 이름은 무시되고 매개 변수가 모두 중요합니다. 그래서 물음표'? '가 더 좋습니다 (제 생각에는). –

1

열 목록에는 10 개의 항목이 있고 값 목록에는 11 개의 항목이 있습니다. 값 목록은

... @City, @State, @Zip, @Phone, @Email, ... 

을 포함하지만

... ShipCity, ShipState, UserPhone, UserEmail, ...