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 4265198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:35:28+00:00 2026-05-21T06:35:28+00:00

Im having a databse with some customer information (customer_nr(primary key), name, address and so

  • 0

Im having a databse with some customer information (customer_nr(primary key), name, address and so on)

The informaton comes from an xml file and is stored in the databse called customer_info.
Now i want to update this table, example if the customer changes his address i want to update the table or, if an customer does not exist i want to insert a new row with the information. Now how do I do this? Ive tried alot of diffrent things but nothing seems to work.

example code:

my insert looks like this:

using (var cmd = new SqlCommand("insert into [customer_info] (custoner_nr, firstName,lastName, adress_1....(and so on))", connection)) {
              cmd.Parameters.AddWithValue("@customer_nr", customerNr);
              cmd.Parameters.AddWithValue("@firstName", fName);
              cmd.Parameters.AddWithValue("@lastName", lName); 
              cmd.ExecuteNonQuery();

my update looks like this:

using (var cmd = new SqlCommand("UPDATE [customer_info] SET [customer_nr] = @customer_nr [firstName] = @firstName, [lastName] = @lastName, WHERE (([customer_nr] = @customer_nr))", connection)) {
                cmd.Parameters.AddWithValue("@custmer_nr", customerNr);
                cmd.Parameters.AddWithValue("@fornamn", fName);
                cmd.Parameters.AddWithValue("@efternamn", lName);
                cmd.ExecuteNonQuery();

I’ve tried to match the customer_nr, something like this:

DataRow row = dataSet.custmer_info.FindBycustomer_nr(t.customerNr);
if (bla != null) {
   updateCustomer(t.kontoNr,t.fName,t.lastname....);
} else {
   insertCustomer(t.kontoNr,t.fName,t.lastname....);
}

If someone understands my problem and could help me i would be so greatful, im really stuck and what ive been testing does not work. =(

  • 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-05-21T06:35:29+00:00Added an answer on May 21, 2026 at 6:35 am

    As far as i can see you are not opening an closing the connection

    using (var cmd = new SqlCommand("UPDATE [customer_info] SET [customer_nr] = @customer_nr [firstName] = @firstName, [lastName] = @lastName, WHERE (([customer_nr] = @customer_nr))", connection)) {
                    cmd.Parameters.AddWithValue("@custmer_nr", customerNr);
                    cmd.Parameters.AddWithValue("@fornamn", fName);
                    cmd.Parameters.AddWithValue("@efternamn", lName);
                    connection.Open();
                    cmd.ExecuteNonQuery();
                    connection.Close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am dealing with a csv file that has some customer information (email, name,
I'm having some trouble updating a row in a MySQL database. Here is the
I'm having some issues with a many-to-many relationship I am trying to create. The
I'm having a system that collects real-time Apache log data from about 90-100 Web
Okay, I'm having some serious issues here. I'm new to this site, and new
We have an application that has multiple identical databases apart from customer customizations. we
Is there a way to update more than one Database having same schema using
Having to upgrade a database schema makes installing a new release of software a
I am having a postgres production database in production (which contains a lot of
I am having problems connecting to a Sqlite database through System.Data.Sqlite. I was trying

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.