How to Store Data in Database using Data table

  • c# - Insert data from DataTable to database table

  • Please explain your question, it is very unclear. Please be more specific and give more information about your situation and what you want to do.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • can you elaborate your question?.

  • ramanathan.raman88 (7/2/2013)


    c# - Insert data from DataTable to database table

    I see you have edited your original post, but it is still not telling us much. Do we need to guess what you want?

    My guess: You have a C# application that connects to a database on a SQL instance. On the C# application you have a grid with data (from where???). You need to write the data from the grid (how many columns, rows; what type of data???) to one (or more????) tables in the database. You want us to give you the statement you need to use to get the data from the grid into the table(s).

    If I'm wrong, please tell us the correct story :w00t:. If my guess is correct, why didn't you write this down in the first place :hehe:.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • You can use a DataAdapter and call the update method, OR write a small loop to loop through the rows in the table and do an insert on each one using SQLConnection. Using the DataAdapter is easier but it essentially does the same thing behind the scenes.

    The probability of survival is inversely proportional to the angle of arrival.

  • The SqlBulkCopy class is the fastest way to load an ADO.NET DataTable to a SQL Server table.

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply