Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8849897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:46:22+00:00 2026-06-14T12:46:22+00:00

So I’m trying to add a contact to my Database using a DataAdapter and

  • 0

So I’m trying to add a contact to my Database using a DataAdapter and Datasets. But I keep getting the same error when I try to add data (see title)

Also when I update my data it doesn’t give any error, but it also doesn’t update anything.

The Add user code

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;
  }

}

The code used to update a user

 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");
}

The code in my form that initiates these processes

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;

}

If you could help it would be fantastic, here is a screenshot of the db I’m using
http://i50.tinypic.com/2s93klk.png

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:46:23+00:00Added an answer on June 14, 2026 at 12:46 pm

    Your insert command is not a valid sql INSERT statement.

    command.CommandText = "INSERT INTO tblContact VALUES(@contactid, @lastname, @firstname,"+ 
                          "@address,@postcode, @city, @gender, @blocked)";
    

    The update commad text is missing a comma

    command.CommandText = "UPDATE tblContact SET LastName = @lastname, FirstName = @firstname," +  
                          "Address = @address, PostCode = @postcode, City = @city, " + 
                          "Gender = @gender, Blocked = @blocked WHERE Id = @contactid";
    

    However, the command fails also because some OleDb provider (like Microsoft.ACE.OleDb.xx) require the ParameterCollection to have the parameters in the exact order in which they appear in the sql text. (No support for named parameters). Your update statement contains the @contactid as last parameter while you add it as first. You could try to change the AddWithValue sequence adding @contactid as last parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to construct a data frame in an Rcpp function, but when I
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.