You must Sign In to post a response.
  • Category: SQL Server

    How to insert Dataset in "My Sql"

    Hello Sir

    Is there any way to insert the whole the dataset in "My Sql"

    Thanks,
    Bhavik Shah
  • #767842
    Hi,

    You want to insert dataset records into database loop through the all entries in your dataset and insert it in database.


    foreach(DataRow dr in ds.Tables[0])
    {
    //now dr contains one cell value insert that into yoru database by writing insert query or call insert stored procedure inside loop.
    }


    Hope this helps you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #767903
    Hi,

    Refer the below..

    Refer the below...
    To pass dataset table data to insert into backend db table in vb.net

    Imports System;
    Imports System.Data
    Imports System.Data.SqlClient

    Dim strCon As String = "Server=192.2.3.4;Database=sample;Uid=sa;Pwd=sn"
    Dim con As New SqlConnection(strCon)
    Dim strSQL As String = "SELECT * from Table1"
    Dim cmd As New SqlCommand(strSQL, con)
    Dim ds As New DataSet()
    Dim da As New SqlDataAdapter(cmd)
    da.Fill(ds)
    Try
    con.Open()
    For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
    Dim strSQL1 As String = "insert into table2 (col1, col2) values ('" & ds.Tables(0).Rows(i).ItemArray(0).ToString() & "','" & ds.Tables(0).Rows(i).ItemArray(1).ToString() & "')"
    Dim cmd1 As New SqlCommand(strSQL1, con)
    cmd.ExecuteNonQuery()
    Next
    con.Close()

    Catch ex As Exception
    Label1.Text = "SQL Query failed: " + ex.Message
    End Try


    Hope this will help you

    Regards,
    SonyShiva
    Never lose hope..You never know what tomorrow will bring

  • #767906
    Hai Bhavik,
    There is no direct way to insert the DataSet values to the MySql database table. You need to get each of the values and then use the Insert statement to insert each of the records.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com


Sign In to post your comments