antonio sanchez

antonio sanchez

  • NA
  • 24
  • 3.8k

connect to database Microsoft SQL Server Compact 3.5 sql in

Jun 28 2016 1:37 PM

hi all

I have a problem to store data in a database created in VS 2008 Microsoft SQL Server Compact 3.5

I have my code where I keep

/////////////////inicio guardar


//cadena de conexion
string partDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
string partBD = System.IO.Path.Combine(partDir, "embarque.sdf");
string connectionstring = string.Empty;
connectionstring = string.Format(@"Data Source = {0}; Password ='root'", partBD);

//File.Delete("embarque.sdf");
// string connString = "Data Source='embarque.sdf'; LCID=1033; Password = root; Encrypt = TRUE;";

//objeto de conexion
SqlCeConnection con = new SqlCeConnection(connectionstring);//"Data Source = ;Persist Security Info=True");
con.Open();
SqlCeCommand agregar = con.CreateCommand();
//comando sql
agregar.CommandText = "INSERT INTO ENVIO values(@RAID,@NPARTE,@CANTIDAD,@VENTANA,@LIDER,@FECHA)";
//con.Open();
try
{

foreach (DataRow row in dt.Rows)
{
agregar.Parameters.Clear();

agregar.Parameters.AddWithValue("@RAID", Convert.ToString(row["Raid"].ToString()));
agregar.Parameters.AddWithValue("@NPARTE", Convert.ToString(row["Nparte"].ToString()));
agregar.Parameters.AddWithValue("@CANTIDAD", Convert.ToString(row["Cantidad"].ToString()));
agregar.Parameters.AddWithValue("@VENTANA", Convert.ToString(row["Ventana"].ToString()));
agregar.Parameters.AddWithValue("@LIDER", Convert.ToString(row["Lider"].ToString()));
agregar.Parameters.AddWithValue("@FECHA", Convert.ToString(row["Fecha"].ToString()));

agregar.ExecuteNonQuery();
}
MessageBox.Show("Datos Agregados");
}
catch (Exception ex)
{
MessageBox.Show("Error al Agregar");
}
finally
{
con.Close();

}

///////////////fin

but I make an error of the path to open the database


Answers (6)