Does not save data in database C #

0

I have this code, but it does not insert the data in the database, but it does not mark any error.

          foreach (DataRow r in datasetexcelcont.Tables[0].Rows) {
            DataRow dr = cobranzaDataSet3.Cartera.NewRow();
            dr[0] = r[0];
            dr[1] = r[1];
            dr[2] = r[2];
            dr[3] = r[3];
            dr[4] = r[4];
            dr[5] = r[5];
            dr[6] = r[6];
            dr[7] = r[7];
            dr[8] = r[8];
            dr[9] = r[9];
            dr[10] = r[10];
            dr[11] = r[11];
            dr[12] = r[12];
            dr[13] = r[13];
            dr[14] = r[14];
            dr[15] = r[15];
            dr[16] = r[16];
            dr[17] = r[17];

            cobranzaDataSet3.Cartera.Rows.Add(dr);
        }
        this.carteraTableAdapter.Update(this.cobranzaDataSet3.Cartera);

If you need more code to understand tell me and put everything. Thanks for helping, I can not find anything. by the way I'm using access database.

    
asked by oscar ramirez 20.02.2017 в 01:58
source

2 answers

1

You may need a SqlCommandBuilder

First you create the command builder:

 SqlCommandBuilder commandBuilder;
 commandBuilder = new SqlCommandBuilder(this.carteraTableAdapter);

then you use the commandBuilder object to generate the queries that you will need for your operations:

this.carteraTableAdapter.DeleteCommand = commandBuilder.GetDeleteCommand(true);
this.carteraTableAdapter.UpdateCommand = commandBuilder.GetUpdateCommand(true);
this.carteraTableAdapter.InsertCommand = commandBuilder.GetInsertCommand(true);

and at the end you will be ready to perform the operations of your code

foreach (DataRow r in datasetexcelcont.Tables[0].Rows) {
    DataRow dr = cobranzaDataSet3.Cartera.NewRow();
    dr[0] = r[0];
    dr[1] = r[1];
    dr[2] = r[2];
    dr[3] = r[3];
    dr[4] = r[4];
    dr[5] = r[5];
    dr[6] = r[6];
    dr[7] = r[7];
    dr[8] = r[8];
    dr[9] = r[9];
    dr[10] = r[10];
    dr[11] = r[11];
    dr[12] = r[12];
    dr[13] = r[13];
    dr[14] = r[14];
    dr[15] = r[15];
    dr[16] = r[16];
    dr[17] = r[17];

    cobranzaDataSet3.Cartera.Rows.Add(dr);
}
this.carteraTableAdapter.Update(this.cobranzaDataSet3.Cartera);
    
answered by 20.02.2017 / 17:23
source
0

this.carteraTableAdapter.Update (this.cobranzaDataSet3.Cartera); // you have to add a command example

adapter.Update (table.Select (null, null, DataViewRowState.Added));

    
answered by 21.02.2017 в 00:48