MySQL Forums
Forum List  »  Spanish

insert 2 tablas distintas
Posted by: rigo lopez
Date: June 29, 2012 01:09PM

saludos, estoy haciendo un programa en VS2010 con c# y tengo una duda sobre como insertar en 2 tablas distintas, el codigo que tengo es esto y me marca error vs.

try
{
MySqlConnection cnn = new MySqlConnection(conn);
const string sql = @"insert into todos(nombre, placa, noeconomico, mpio, rfc, merca, submarca, fecha, modelo, org, chasis, motor, domicilio, tipo, localidad,)
values (@nombre, @placa, @noeco, @mpio, @rfc, @merca, @submarca, @fecha, @modelo, @org, @chasis, @motor, @domicilio, @tipo, @localidad,)";

MySqlConnection cmm = new MySqlConnection(conn);
const string mysql = @"insert into taxi(color, sitio) values (@color, @sitio)";

MySqlCommand.cmd = new MySqlCommand(mysql, cmm);
cmd.Parameters.AddWithValue("@color", cs.color);
cmd.Parameters.AddWithValue("@sitio", cs.sitio);
MySqlCommand cmd = new MySqlCommand(sql, cnn);
cmd.Parameters.AddWithValue("@nombre", cs.nombre);
cmd.Parameters.AddWithValue("@placa", cs.placa);
cmd.Parameters.AddWithValue("@noeco", cs.noeco);
cmd.Parameters.AddWithValue("@mpio", cs.lcl);
cmd.Parameters.AddWithValue("@rfc", cs.rfc);
cmd.Parameters.AddWithValue("@merca", cs.marca);
cmd.Parameters.AddWithValue("@submarca", cs.submarca);
cmd.Parameters.AddWithValue("@fecha", cs.fecha);
cmd.Parameters.AddWithValue("@modelo", cs.modelo);
cmd.Parameters.AddWithValue("@org", cs.org);
cmd.Parameters.AddWithValue("@chasis", cs.chasis);
cmd.Parameters.AddWithValue("@motor", cs.motor);
cmd.Parameters.AddWithValue("@domicilio", cs.domicilio);
cmd.Parameters.AddWithValue("@tipo", cs.tipos);
cmd.Parameters.AddWithValue("@localidad", cs.rancho);

cnn.Open();
int result = Convert.ToInt32(cmd.ExecuteNonQuery());
MessageBox.Show("El Registro ha sido almacenado", "Listo", MessageBoxButtons.OK);
}
catch (MySqlException ex)
{
MessageBox.Show("eRROR" + ex.Message);
}
}

alguien, ayuda, gracias! se que se tiene que hacer en un solo insert, pero no tengo idea de como!



Edited 1 time(s). Last edit at 06/29/2012 01:12PM by rigo lopez.

Options: ReplyQuote


Subject
Views
Written By
Posted
insert 2 tablas distintas
1980
June 29, 2012 01:09PM
760
June 30, 2012 06:02AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.