1 Replies - 477 Views - Last Post: 28 June 2016 - 11:09 AM Rate Topic: -----

#1 antonio sanchez   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-June 16

connect to database Microsoft SQL Server Compact 3.5 sql in C# smart d

Posted 28 June 2016 - 10:39 AM

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

This post has been edited by Skydiver: 28 June 2016 - 10:53 AM
Reason for edit:: Put code in code tags.


Is This A Good Question/Topic? 0
  • +

Replies To: connect to database Microsoft SQL Server Compact 3.5 sql in C# smart d

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14409
  • View blog
  • Posts: 57,772
  • Joined: 12-June 08

Re: connect to database Microsoft SQL Server Compact 3.5 sql in C# smart d

Posted 28 June 2016 - 11:09 AM

Have you tried the format found here?

https://www.connecti...server-compact/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1