Hi anirudhp,
Refer below code.
C#
protected void InsertIntoCloud(object sender, EventArgs e)
{
DataTable dt = new DataTable(); ;
string constr = ConfigurationManager.ConnectionStrings["constrLocal"].ConnectionString;
using (MySqlConnection con = new MySqlConnection(constr))
{
using (MySqlCommand cmd = new MySqlCommand("SELECT Name, Country FROM Customers"))
{
using (MySqlDataAdapter sda = new MySqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
}
}
}
foreach (DataRow dr in dt.Rows)
{
string constr = ConfigurationManager.ConnectionStrings["constrCloud"].ConnectionString;
using (MySqlConnection con = new MySqlConnection(constr))
{
using (MySqlCommand cmd = new MySqlCommand("INSERT INTO Customers (Name, Country) VALUES (@Name, @Country)"))
{
using (MySqlDataAdapter sda = new MySqlDataAdapter())
{
cmd.Parameters.AddWithValue("@Name", name);
cmd.Parameters.AddWithValue("@Country", country);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
}
VB.Net
Protected Sub InsertIntoCloud(ByVal sender As Object, ByVal e As EventArgs)
Dim dt As DataTable = New DataTable()
Dim constr As String = ConfigurationManager.ConnectionStrings("constrLocal").ConnectionString
Using con As MySqlConnection = New MySqlConnection(constr)
Using cmd As MySqlCommand = New MySqlCommand("SELECT Name, Country FROM Customers")
Using sda As MySqlDataAdapter = New MySqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
sda.Fill(dt)
End Using
End Using
End Using
For Each dr As DataRow In dt.Rows
Dim constr As String = ConfigurationManager.ConnectionStrings("constrCloud").ConnectionString
Using con As MySqlConnection = New MySqlConnection(constr)
Using cmd As MySqlCommand = New MySqlCommand("INSERT INTO Customers (Name, Country) VALUES (@Name, @Country)")
Using sda As MySqlDataAdapter = New MySqlDataAdapter()
cmd.Parameters.AddWithValue("@Name", name)
cmd.Parameters.AddWithValue("@Country", country)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
End Using
Next
End Sub
For more details on insert in MySQL refer