그래서 DataAdapter 및 Datasets를 사용하여 데이터베이스에 연락처를 추가하려고합니다. 그러나 데이터를 추가하려고 할 때 계속 동일한 오류가 발생합니다. (제목 참조)C# OleDbException 처리되지 않았습니다 : 하나 이상의 필수 매개 변수에 값이 지정되지 않았습니다.
또한 데이터를 업데이트해도 오류는 발생하지 않지만 아무것도 업데이트하지 않습니다.
추가 사용자 코드
public void AddUser(Contact contact) {
command.Connection = getConnection();
command.CommandText = "INSERT INTO tblContact VALUES(Id = @contactid, LastName = @lastname, FirstName = @firstname, Address = @address"
+ "PostCode = @postcode, City = @city, Gender = @gender, Blocked = @blocked)";
command.Parameters.AddWithValue("@contactid", contact.AccountId);
command.Parameters.AddWithValue("@lastname", contact.LastName);
command.Parameters.AddWithValue("@firstname", contact.FirstName);
command.Parameters.AddWithValue("@address", contact.Address);
command.Parameters.AddWithValue("@postcode", contact.PostCode);
command.Parameters.AddWithValue("@city", contact.City);
bool gender = (contact.Gender == Gender.Male ? true : false);
command.Parameters.AddWithValue("@gender", gender);
command.Parameters.AddWithValue("@blocked", contact.Blocked);
try {
adapter.InsertCommand = command;
adapter.Update(dsCon, "tblContact");
adapter.Fill(dsCon, "tblContact");
}
catch (Exception e) {
String code = e.Message;
}
}
사용자에게
public void ModifyUser(Contact contact)
{
command.Connection = getConnection();
command.CommandText = "UPDATE tblContact SET LastName = @lastname, FirstName = @firstname, Address = @address"
+ "PostCode = @postcode, City = @city, Gender = @gender, Blocked = @blocked "
+ "WHERE Id = @contactid";
command.Parameters.AddWithValue("@contactid", contact.AccountId);
command.Parameters.AddWithValue("@lastname", contact.LastName);
command.Parameters.AddWithValue("@firstname", contact.FirstName);
command.Parameters.AddWithValue("@address", contact.Address);
command.Parameters.AddWithValue("@postcode", contact.PostCode);
command.Parameters.AddWithValue("@city", contact.City);
command.Parameters.AddWithValue("@gender", contact.Gender);
command.Parameters.AddWithValue("@blocked", contact.Blocked);
adapter.UpdateCommand = command;
adapter.Update(dsCon, "tblContact");
adapter.Fill(dsCon, "tblContact");
}
당신이 그것을 도울 수 있다면 이러한 프로세스
private void btnSave_Click(object sender, EventArgs e) {
Contact currentContact = new Contact();
currentContact.AccountId = Int32.Parse(lblID.Text);
currentContact.LastName = txtLastName.Text;
currentContact.FirstName = txtName.Text;
currentContact.Address = txtStreet.Text;
currentContact.PostCode = Int32.Parse(txtPostalCode.Text);
currentContact.City = txtCity.Text;
currentContact.Gender = (rdbMale.Checked == true ? Gender.Male : Gender.Female);
currentContact.Blocked = chkBlocked.Checked;
currentContact.Address = txtStreet.Text;
if(isNewContact){
currentContact.AccountId = (manager.GetContacts().Last().AccountId + 1);
manager.GetOleDbManager().AddUser(currentContact);
} else {
manager.GetOleDbManager().ModifyUser(currentContact);
}
currentContact.Categories = new List<Category>();
foreach (Object c in lstCategories.SelectedItems) {
currentContact.Categories.Add((Category)c);
}
isNewContact = false;
}
을 시작하는 내 양식의 코드를 업데이트하는 데 사용되는 코드를 환상적 일 것입니다. 사용중인 db의 스크린 샷입니다. http://i50.tinypic.com/2s93klk.png
+1 나는 같은 대답을 썼다. 40 초 만에 나를 때려 라. –
Faill! o.O 복사 붙여 넣기를 위해 무엇입니까? –
xS로 업데이트 절차가 여전히 작동하지 않습니다 –