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

  • Home
  • SEARCH
  • 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 8132187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:17:04+00:00 2026-06-06T09:17:04+00:00

I am a newbie to c#. I am trying to insert the values from

  • 0

I am a newbie to c#. I am trying to insert the values from the text box into the table in my database.

Table Name : address

Fields : name(varchar(50)),
age(int),
city(nchar(10))

When i try to retrieve the values from the database it is working perfectly.
Here is my code. Please help me rectify it.

            string s = @"Data      Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated  Security=True;User Instance=True";
            SqlConnection a = new SqlConnection(s);

            a.Open();
            SqlCommand comm = new SqlCommand("INSERT INTO [address](name,age,city)  VALUES(@na,@ag,@ci)");
            string na = textBox1.Text;
            int ag = int.Parse(textBox2.Text);
            string ci = textBox3.Text;

            comm.Parameters.Add("@na", System.Data.SqlDbType.VarChar,50).Value = na;
            comm.Parameters.Add("@ag", System.Data.SqlDbType.Int).Value = ag;
            comm.Parameters.Add("@ci", System.Data.SqlDbType.NChar,10).Value = ci;
            comm.Connection = a;
            comm.ExecuteNonQuery();
            MessageBox.Show("okay");
            a.Close();

The values are not reflected in the database.

  • 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-06T09:17:05+00:00Added an answer on June 6, 2026 at 9:17 am

    try with this code :

    string connectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated  Security=True;User Instance=True";
    
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
    
        using (SqlCommand insertCommand = connection.CreateCommand())
    
            {
                insertCommand.CommandText = "INSERT INTO address(name,age,city) VALUES (@na,@ag,@ci)";
                insertCommand.Parameters.Add("@na", na);
                insertCommand.Parameters.Add("@ag", ag);
                insertCommand.Parameters.Add("@ci", ci);
    
    
                insertCommand.Connection.Open();
                insertCommand.ExecuteNonQuery();
    
    
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im a newbie ih php.Im trying to show drop down list values from database
I am trying to store some parsed feed contents values in Sqlite database table
I'm an SQL newbie and trying to figure out how to insert multiple table
I am trying to do a batch insert into a database, to try and
I am a xml newbie trying to create a XDocument type from a xml
I'm a newbie to asp .net and c# world. I'm trying to insert a
I am a newbie to Database programming. After inserting a couple of rows into
I am a LINQ newbie trying to use it to acheive the following: I
I a newbie trying to write a [Ruby ON Rails] spec to make sure
I'm a machine learning newbie trying to understand how Adaboost works. I've read many

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.