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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:04:09+00:00 2026-06-02T21:04:09+00:00

Could somebody tell me why this isn’t adding the values to the database. The

  • 0

Could somebody tell me why this isn’t adding the values to the database. The form runs fine and doesn’t return any errors.

    private void button1_Click(object sender, EventArgs e)
    {
        SqlConnection connection = new SqlConnection();
        SqlCommand command = new SqlCommand();

        connection.ConnectionString = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\John\Documents\Setup.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");

        command.Parameters.AddWithValue("@userName", textBox1.Text);
        command.Parameters.AddWithValue("@passWord", textBox2.Text);
        command.CommandText = "INSERT INTO Setup (userName, password) VALUES(@userName, @passWord)";



        try
        {
            connection.Open();
            int rowsAffected = command.ExecuteNonQuery();

        }
        catch (Exception ex)
        {
            // handle exception
        }
        finally
        {
            connection.Close();
        }


    }

FYI: I’m a “newbie” My database is called Setup. I’ve manually added a table called myTable with 2 columns of userName and another one called password both set at nchar(50)

  • 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-02T21:04:10+00:00Added an answer on June 2, 2026 at 9:04 pm

    You need to specify the Table, not the database (which gets used in the connection string). Added the schema prefix to the table name:

    command.CommandText = "INSERT INTO dbo.myTable (userName, password) VALUES (@userName, @passWord)";
    

    And add:

    command.Connection = connection;
    

    to associate your Command object with the connection object.

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

Sidebar

Related Questions

Could somebody tell me why I'm getting blank rows after running this code? ...
This is probably very simple, but could somebody tell me how to get the
Could somebody tell me which drupal module is this site using: http://gallery.menalto.com/forum Also could
could somebody please tell me why this code fails. url is nil after calling
I stumbled upon this one-liner: [float(n)-50 for n in range(100)] Could somebody tell me
Could somebody tell me the difference between: int *p; p=(int*)malloc(10*sizeof(int)); free(p); or int *p;
I'm implementing now CPU schedule algorithms FCFS, SJF and Round Robin. Could somebody tell
Could somebody tell me what is the proper way to convert a NSString* to
Could somebody tell me how can I convert byte[] to ArrayList by using C#
Could somebody please tell me how I can configure iReport 3.5 (nb) to use

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.