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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:53:17+00:00 2026-05-14T05:53:17+00:00

I have data coming into my Model, how do I setup to insert the

  • 0

I have data coming into my Model, how do I setup to insert the data in a table?

    public string Name { get; set; }
    public string Address { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Zip { get; set; }

    public Info()
    {
        using (SqlConnection connect = new SqlConnection(connections))
        {
            string query = "Insert Into Personnel_Data (Name, StreetAddress, City, State, Zip, HomePhone, WorkPhone)" +
                "Values('" + Name + "','" + Address + "','" + City + "','" + State + "','" + Zip + "','" + ContactHPhone + "','" + ContactWPhone + "')";

            SqlCommand command = new SqlCommand(query, connect);
            connect.Open();
            command.ExecuteNonQuery();
        }
    }

The Name, Address, City, and so on is null when the query is being run. How do I set this up?

  • 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-14T05:53:18+00:00Added an answer on May 14, 2026 at 5:53 am

    You need to initialize your properties in constructor before you use it:

    public string Name { get; set; }
    public string Address { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Zip { get; set; }
    public string ContactHPhone { get;set; }
    public string ContactWPhone { get;set; }
    
    public Info(string name, string address, string city, string state, string zip, string contactHPhone, string contactWPhone)
    {
        Name = name;
        Address = address;
        City = city;
        State = state;
        Zip = zip;
        ContactHPhone = contactHPhone;
        ContactWPhone = contactWPhone;
        using (SqlConnection connect = new SqlConnection(connections))
        {
            string query = "Insert Into Personnel_Data (Name, StreetAddress, City, State, Zip, HomePhone, WorkPhone)" +
                "Values('" + Name + "','" + Address + "','" + City + "','" + State + "','" + Zip + "','" + ContactHPhone + "','" + ContactWPhone + "')";
    
            SqlCommand command = new SqlCommand(query, connect);
            connect.Open();
            command.ExecuteNonQuery();
        }
    }
    

    Edited:

    The better way is to use parameters in your SQL string:

    using (SqlConnection connect = new SqlConnection(connections))
    {
        string query = "Insert Into Personnel_Data (Name, StreetAddress, City, State, Zip, HomePhone, WorkPhone) Values(@name, @address, @city, @state, @zip, @contactHPhone, @contactWPhone)";
    
        SqlCommand command = new SqlCommand(query, connect);
        command.Parameters.AddWithValue("name", Name);
        command.Parameters.AddWithValue("address", Address);
        command.Parameters.AddWithValue("city", City);
        command.Parameters.AddWithValue("state", State);
        command.Parameters.AddWithValue("zip", Zip);
        command.Parameters.AddWithValue("contactHPhone", ContactHPhone);
        command.Parameters.AddWithValue("contactWPhone", ContactWPhone);
        connect.Open();
        command.ExecuteNonQuery();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 5 rows of data coming into my database every 2 hours from
I have a table in C#, the data is coming from an Excel file.
I have data coming from an external system (in CSV form). The data contains
I have data in this format coming from a database... BUS 101S Business and
I have a stream of data coming in over the serial line from an
I have a function that will parse some data coming in. My problem is
I have couple of formulas and data coming from database. I want to refresh
I have a requirement where i have to read data streams coming on serial
I have amount attribute in coredata model with string datatype. I need to find
I'm storing some very basic information data sources coming into my application. These data

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.