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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:31:02+00:00 2026-05-11T15:31:02+00:00

How can we insert the values of datatable in SQL using c#? And the

  • 0

How can we insert the values of datatable in SQL using c#? And the second question is how we can copy the SQL table into datatable variable?

  • 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. 2026-05-11T15:31:03+00:00Added an answer on May 11, 2026 at 3:31 pm

    UPDATE: One thing this answer didn’t have in the past is links to information for SQL and database newbies, so I will put some relevant links here as well so that you (or anyone else) can brush up on their SQL and other database design skills.

    • W3 Schools SQL Tutorial
    • Database Design Tutorial

    UPDATE 2: Here is an example of filling a datatable:

    //Namespace References using System.Data; using System.Data.SqlClient  /// <summary> /// Returns a DataTable, based on the command passed /// </summary> /// <param name='cmd'> /// the SqlCommand object we wish to execute /// </param> /// <returns> /// a DataTable populated with the data /// specified in the SqlCommand object /// </returns> /// <remarks></remarks>  public static DataTable GetDataTable(SqlCommand cmd) {     try     {         // create a new data adapter based on the specified query.         SqlDataAdapter da = new SqlDataAdapter();          //set the SelectCommand of the adapter         da.SelectCommand = cmd;          // create a new DataTable         DataTable dtGet = new DataTable();          //fill the DataTable         da.Fill(dtGet);          //return the DataTable         return dtGet;       }       catch (SqlException ex)       {           MessageBox.Show(ex.Message);       }       catch (Exception ex)       {           MessageBox.Show(ex.Message);       }   }  

    A lot of this is taken from another answer I have written previously, but it goes into detail about your exact issues:

    Original Answer:

    This sounds like you more or less need a basic introduction to connecting and manipulating a database from C#. The above poster said to look into LINQ to SQL, but you can also look into the more basic underlying framework of ADO.NET which will get you to understand the basics of how it works.

    Also, you can use this site right here for a number of different database tutorials for C#.

    Edit: More information from C# Station, CodeProject, and Codersource

    Edit 2: If you are interested in things like Linq to SQL as others have mentioned above, here are some tutorials from C# Corner, and C-Sharp Online

    Edit 3: Others would also suggest things such as the ADO.NET Entity Framework. I would not necessarily suggest this for beginners who still need to grasp the fundamentals of working with a database. Here is some information from the MSDN Overview

    Simple Example (This is pulled directly from the C# Station link given above)

    Listing 1. Using a SqlConnection

    using System; using System.Data; using System.Data.SqlClient;  /// <summary> /// Demonstrates how to work with SqlConnection objects /// </summary> class SqlConnectionDemo {     static void Main()     {         // 1. Instantiate the connection         SqlConnection conn = new SqlConnection(             'Data Source=(local);Initial Catalog=Northwind;              Integrated Security=SSPI');          SqlDataReader rdr = null;          try         {             // 2. Open the connection             conn.Open();              // 3. Pass the connection to a command object             SqlCommand cmd =                  new SqlCommand('select * from Customers', conn);              //             // 4. Use the connection             //              // get query results             rdr = cmd.ExecuteReader();              // print the CustomerID of each record             while (rdr.Read())             {                 Console.WriteLine(rdr[0]);             }         }         finally         {             // close the reader             if (rdr != null)             {                 rdr.Close();             }              // 5. Close the connection             if (conn != null)             {                 conn.Close();             }         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 99k
  • Answers 99k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, reflection does not directly enable a class to change… May 11, 2026 at 7:49 pm
  • Editorial Team
    Editorial Team added an answer Use this: int yourInteger; string newItem; newItem = textBox1.Text.Trim(); Int32… May 11, 2026 at 7:49 pm
  • Editorial Team
    Editorial Team added an answer You do it with the setsockopt() call, by using the… May 11, 2026 at 7:49 pm

Related Questions

I am trying to trace a deadlock that is occurring in our SQL 2005
In my last job, we worked on a very database-heavy application, and I developed
I want to record user states and then be able to report historically based
There is a need from a customer to log every data change to a
I hope this is a simple enough question for any SQL people out there...

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.