1
Good night! Personal, I have a select working normally and displaying the result in a datagridviewer all straight though, I need to take the result of this query that is done in the mysql database of the X server and write in an identical table in the database of the Y server, how do I enter a select in c#?
Below is my query.
try
{
conexao = new MySqlConnection("server=xxxxx;database=xxxx;uid=xxx;pwd=xxxx;port=3306;SSL Mode = none");
DateTime DataFechInicio = dtpFechInicio.Value;
DateTime DataFechFim = dtpFechFim.Value;
strSQL = "SELECT " +
"p.Nome," +
"v.Vencimento," +
"Concat('R$ ',Format(v.Valor,2,'de_DE')) as Valor," +
"bd.Descricao as 'Centro de Custo'" +
"FROM pessoa p " +
"INNER JOIN pedido pd " +
"ON p.idpessoa = pd.fornecedor " +
"INNER JOIN pedvenc v " +
"ON v.idpedido = pd.idpedido " +
"INNER JOIN base_dpto bd " +
"ON bd.CCUSTO = v.CCUSTO " +
"WHERE v.vencimento " +
"BETWEEN '" + DataFechInicio.ToString("yyyy-MM-dd") + "' " +
"AND '" + DataFechFim.ToString("yyyy-MM-dd") + "' " +
"AND pd.cnsstatus = 'FECHADO' " +
"AND pd.cnscanmom IS NULL " +
"ORDER BY nome ASC";
da = new MySqlDataAdapter(strSQL, conexao);
DataTable dt = new DataTable();
da.Fill(dt);
dgvFechDados.DataSource = dt;
conexao.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw;
}
finally
{
conexao.Close();
conexao = null;
}
Isn’t it easier to do it on the server anyway? It might be something like this
insert into serverY.database.tabela(campos...) select campos from serverX.database.tabela
– Ricardo Pontual