Development in .net Compact (Smart Device)

4

I am developing an application in .NET Compact for Windows Embedded with C # language and SQL Compact 3.5 database.

The application has 3 columns with several rows, I have 2 columns that show in their rows an information already established in the database and in the third column would be what the user types, this is mounted in a DataGrid where call the information of the database, I have a Textbox where the information that goes in the third column is placed and two buttons one to edit and another to save.

The following problem occurs:

When I want to run from the computer where I am developing, I get a error nativo 25009 that does not stop me from passing the line to open the database, on the other hand when I run it on the device, it throws me a mapping error. I already check the path and the path of the database is the correct disk C/Carpeta Base de datos and inside there is my base de datos .sdf ,

I attach the source code:

    private void btnEditar_Click(object sender, EventArgs e)
    {
        DataGridCell currentCell;
        string currentCellData;
        //  Se obtiene el texto a poner en la celda actual.
        currentCellData = txtCantidad.Text;
        //  Se obtiene la celda actual.
        currentCell = dtFrutas.CurrentCell;
        //  Se asigna la data a la celda actual.
        dtFrutas[currentCell.RowNumber, currentCell.ColumnNumber] = currentCellData;
        txtCantidad.Text = "";
    }


    private void btnGuardar_Click(object sender, EventArgs e)
    {
        SqlCeConnection conn = null;
        //SqlCeConnection con = new SqlCeConnection("Data Source =\"\Program Files\FrutayPastelino\MisPedidos.sdf\";");
        SqlCeConnection con = new SqlCeConnection("Data Source = C:\Base de datos\MisPedidos.sdf");
        //con.Open();
        SqlCeCommand ad = new SqlCeCommand("UPDATE Fruta SET Cantidad = @cantidad WHERE Codigo_Integra = @codigo_integra", con);
        con.Open(); // Error nativo 25009 en el ordenador.

        try
        {
           ad.Parameters.AddWithValue("@cantidad",txtCantidad.Text);
           ad.Parameters.AddWithValue("@codigo_integra", " ");   //ERROR DE MAPEO EN EL DISPOSITIVO
           //ad.ExecuteNonQuery();
            MessageBox.Show("Pedido bien");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        finally
        {  
            con.Close();
            ad.Dispose();
        }
    }


    private void Form1_Load(object sender, EventArgs e)
    {
        // TODO: esta línea de código carga datos en la tabla 'misPedidosDataSet.Fruta' Puede moverla o quitarla según sea necesario.
        this.frutaTableAdapter.Fill(this.misPedidosDataSet.Fruta);
    }
    
asked by Cristian R.M 14.07.2016 в 02:06
source

2 answers

1

Place the following code in the btnSave and update your connection string.

string ruta;
ruta = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
MessageBox.Show(ruta);

On the other hand, when you debug your application in your device / emulator, check and verify that the Copy to Output Directory of your .sdf file property has the appropriate value, so it will not be overwritten the next time.

In that MessageBox is the place where your program runs, which gives us the right path. As far as I was investigating in PocketPC the routes have no letters and every route starts with double backslash \ so you mention the new error, it seems that the database is in the right place, however, apparently, the "code integra" must be numeric and since you are assigning an empty field, it throws the error.

What should go in the "code integra" is the ID of the fruit that you are going to update.

 UPDATE Fruta SET Cantidad = @cantidad WHERE Codigo_Integra = @codigo_integra

This means: we update the Fruit table, the new value of the field @Cantidad will be what is in the variable cantidad , this applies to all the elements that meet the condition: Codigo_Integra (field of the Fruits table) is equal to @codigo_integra (the value you assign).

Check the information of the grid, I assure you that there is the unique ID (integral_code) that you need to update the amount of the fruit: D and if it exists, save it temporarily in a hidden textbox and in each clean update that textbox to avoid mixing quantities with other products.

In case the ID of the grid is missing, check the SQL query and add that missing ID (integral_code), then you can hide it from view, but the data will already be present

    
answered by 18.07.2016 в 19:19
0

Try changing this line

SqlCeConnection con = new SqlCeConnection("Data Source = C:\Base de datos\MisPedidos.sdf");
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

By

SqlCeConnection con = new SqlCeConnection(@"Data Source = C:\Base de datos\MisPedidos.sdf");
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Another tip, is that you do not leave blank spaces in the path, for example "Base de datos" , I would recommend using something more compact like: C:\bd\pedidos.sdf

Edited

Presiamente the same thing happened to me and I realized that all the time I was putting misdirected the file .sdf

            using (var cnn = new SqlCeConnection("Data Source=MyData.sdf;Persist Security Info=False;"))
        {
            var command = new SqlCeCommand("update...", cnn);
            command.CommandType = System.Data.CommandType.Text;
            command.Parameters.AddWithValue("@p1", "valor3");
            command.Parameters.AddWithValue("@p2", "valor2");

            try
            {
                cnn.Open();
                command.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
    
answered by 26.07.2016 в 16:37