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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:31:33+00:00 2026-05-27T03:31:33+00:00

I have read TONS of tutorials, articles and whatever regarding my issue and honestly,

  • 0

I have read TONS of tutorials, articles and whatever regarding my issue and honestly, due to my lack of experience I can’t twist my fingers around this one so I hope some of you guys can help me out 🙂

I am working on a project (simply to learn how to program so it’s probably very basic), but I have this “News” page where I can update and delete data using a GridView.

Now I would like to INSERT something into my database using 3 textboxes and 1 submit button.

I have 3 rows that has to be inserted:

  1. Headline
  2. Date
  3. Content/the news itself.

Which are stored under NyhedTB from the connectionstring: BoligStjernenConnectionString

My query looks like this:

INSERT INTO [NyhedTB] ([NyhedDato], [NyhedTitel], [NyhedTekst])
VALUES (@NyhedDato, @NyhedTitel, @NyhedTekst)

I read on the internet that this code should do the magic for me (I will have to insert my own values ofc.):

static void Insert()
{
    try
    {
        string connectionString =
            "server=.;" +
            "initial catalog=employee;" +
            "user id=sa;" +
            "password=sa123";
        using (SqlConnection conn =
            new SqlConnection(connectionString))
        {
            conn.Open();
            using (SqlCommand cmd =
                new SqlCommand("INSERT INTO EmployeeDetails VALUES(" +
                    "@Id, @Name, @Address)", conn))
            {
                cmd.Parameters.AddWithValue("@Id", 1);
                cmd.Parameters.AddWithValue("@Name", "Amal Hashim");
                cmd.Parameters.AddWithValue("@Address", "Bangalore");

                int rows = cmd.ExecuteNonQuery();

                //rows number of record got inserted
            }
        }
    }
    catch (SqlException ex)
    {
        //Log exception
        //Display Error message
    }
}

I looked at this code and thought it should be easy enough but really, I can’t figure it out.

  • 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-27T03:31:33+00:00Added an answer on May 27, 2026 at 3:31 am

    Here is some advice to get you going, learning programming is a lot of
    trial and error.

    1. Start off basic, litrally put three textboxes on a form/page and a
      button.

    2. Double click the button to go the code-behind and view the buttons
      click event.

    3. Paste in the body of code included with your question (everything in the try-catch).

    4. Put a break-point on the Public Void Button_Click line of code and press F11 to
      step through the code.

    “one thing is having the code-behind working but how to make the buttons and textboxes working is still a misery”*

    Put the textbox as the value rather than your hardcoded values:

    cmd.Parameters.AddWithValue(“@Address”, textBox1.Text);

    You also should not insert the Id value, instead modify the EmployeeDetails table and set the ID column to in the properties set Identity Specification (IS Identity) = True. Then right click the ID column and set Primary Key.

    Post any error messages you encounter here and when you do get get it working, an additional exercise (that will be very valuable for you) would use a database stored procedure rather than ad-hoc SQL, to safe-guard against sql-injection attacks.

    I’m assuming you have SQL Server installed and have a ’employee’ database with a table called EmployeeDetails.

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

Sidebar

Related Questions

I've read tons of other questions and googled the issue, but I can only
I have read a lot that LISP can redefine syntax on the fly, presumably
I have read (or perhaps heard from a colleague) that in .NET, TransactionScope can
I have read tutorials and several stack overflow posts that suggest I should use
I have read that some of the JVMs out there can optimize code execution
I must have read tons of solutions online, but for some idiotic reason I
I have read quite a lot of R docs, but I can't find anything
I've read through tons of posts and articles and haven't found a fix that
Have read some great tutorials online about the new storyboarding feature of xcode 4.2.
I have read several articles about UITableView, including the official doc and some on

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.