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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:10:33+00:00 2026-06-12T04:10:33+00:00

This is my first time working with DB. I’ve decided to create a DB

  • 0

This is my first time working with DB.
I’ve decided to create a DB with two tables – “Team”, “Player”
I want to add a new player to the “Player” table.
The “Player” table consists of the following columns: ID(autonumber), FirstName, LastName, TeamID

In order to do so, I’ve created three text boxes for the FirstName, LastName, TeamID
Note that I did not treat the “ID” since it’s an autonumber and should be added automatically
The Button1_click should add the new row eventually.

Here’s my code:

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            connection = new OleDbConnection(connectionString);
        }
        catch
        { }
        try
        {
            connection.Open();

            OleDbCommand command = new OleDbCommand("INSERT INTO Player VALUES ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')");

            command.ExecuteNonQuery();

            connection.Close();

        }
        catch
        { }
  • 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-12T04:10:34+00:00Added an answer on June 12, 2026 at 4:10 am

    When you write an INSERT string that doesn’t include the column names you should specify every column in the values. In your case you need to add

     string sqlText = "INSERT INTO Player (FirstName, LastName, TeamID) VALUES ('" 
                      + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')"); 
    

    However this code is wrong for another reason. Never write sql strings concatenating input text typed by the user. This will cause errors or, worse, lead to Sql Injection

       using(connection = new OleDbConnection(connectionString))
       { 
            connection.Open(); 
            string sqlText = "INSERT INTO Player (FirstName, LastName, TeamID) " + 
                             "VALUES (?, ?, ?)"; 
            OleDbCommand command = new OleDbCommand(sqlText, connection); 
            command.Parameters.AddWithValue("@First", textBox1.Text);
            command.Parameters.AddWithValue("@Last", textBox2.Text);
            command.Parameters.AddWithValue("@team", textBox3.Text);
            command.ExecuteNonQuery(); 
        }
    

    There is another problem. If the TeamID field is a numeric field you need to convert the textbox3.text input in a numeric value to correctly use the AddWithValue method

            int teamID;
            if(!Int32.TryParse(textBox3.Text, out teamID))
                 throw new ArgumentException("Type a valid TeamID number, please!");
            command.Parameters.AddWithValue("@team", teamID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time working with python. I'm trying to create a dictionary
This is my first time working with Objective-C, and I keep trying to create
I'm pretty new to python. This is my first time working with classes in
This is my first time working with a WPF datagrid. From what I understand
This is my first time working with file i/o in java, and it's not
this is my first time asking a question on stackoverflow. I'm working on a
This is my first time using this site and I am quite new to
This is my first time working on php code. I've put some printf code
I am currently working on an ASP.NET MVC2 project. This is the first time
This is my first time working with a webservice and I tried looking up

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.