How to insert Dataset in "My Sql"
Hello SirIs there any way to insert the whole the dataset in "My Sql"
Thanks,
Bhavik Shah
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.
}
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