none
Send Values from datagridview back to Access database RRS feed

  • Question

  • I cant manage the problem i have found this way but it says an error

            private void atj()
            {

                olecnn.Open();
                for (int i = 0; i <= tipsobjektiDataGridView.Rows.Count; i++)
                {
                    addapter = new OleDbDataAdapter("insert into objekti values(" + tipsobjektiDataGridView.Rows[i].Cells[2].Value + ")", olecnn);
                    addapter.Fill(ds,"dati");
                }
                olecnn.Close();
        }

    Error is:Number of query values and destination fields are not the same.

    Tuesday, July 23, 2013 9:23 AM

Answers

  • Hi tom,

    According to your description,I found out that  your insert into  statement  is wrong.

    Please check your insert into statement.

    Such as “insert into Product(PId,PName,PSize) values(100,’aaa’,20)”  .

    Make sure that the count of the columns you want to insert into are equals to the count of the values.

    I am glad to help you.

    Thursday, July 25, 2013 3:50 AM
  • Hi Toms

    As herro8 said, I suggest you check the table schema first.

    The count of columns inserted should be equal to the fields in the table.

    This is an example:

    "INSERT Region (RegionID, RegionDescription) VALUES (5, 'NorthWestern')";

    For details,you can see:

    How to: Insert New Records into a Database

    http://msdn.microsoft.com/en-us/library/vstudio/ms233812(v=vs.100).aspx/html

    Besides,if you use the default DataGridView, the  statement 'i <= tipsobjektiDataGridView.Rows.Count'  should change to 'i < tipsobjektiDataGridView.Rows.Count -1' ,becasue the index of rows starts from 0.

    Hope it can help you.

    Thursday, July 25, 2013 5:59 AM

All replies

  • Hi tom,

    According to your description,I found out that  your insert into  statement  is wrong.

    Please check your insert into statement.

    Such as “insert into Product(PId,PName,PSize) values(100,’aaa’,20)”  .

    Make sure that the count of the columns you want to insert into are equals to the count of the values.

    I am glad to help you.

    Thursday, July 25, 2013 3:50 AM
  • Hi Toms

    As herro8 said, I suggest you check the table schema first.

    The count of columns inserted should be equal to the fields in the table.

    This is an example:

    "INSERT Region (RegionID, RegionDescription) VALUES (5, 'NorthWestern')";

    For details,you can see:

    How to: Insert New Records into a Database

    http://msdn.microsoft.com/en-us/library/vstudio/ms233812(v=vs.100).aspx/html

    Besides,if you use the default DataGridView, the  statement 'i <= tipsobjektiDataGridView.Rows.Count'  should change to 'i < tipsobjektiDataGridView.Rows.Count -1' ,becasue the index of rows starts from 0.

    Hope it can help you.

    Thursday, July 25, 2013 5:59 AM
  • Also, you should be using the Command.ExecuteNonQuery() rather than the Adapter.Fill() ... you're not Filling a DataTable.

    ~~Bonnie Berent DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Thursday, July 25, 2013 3:50 PM
  • Hi TomsPriedolins,

    Please remember to mark the replies as answers if they help.

    If you have any questions, please let us know.

    Thanks

    Best Regards


    Starain Chen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Saturday, July 27, 2013 10:54 AM
    Moderator
  • Hi TomsPriedolins,

    Since we haven't heard from you for a long time, I temporarily close this case. I mark useful reply as answer. If you have any concerns, please free feel toreopen it or submit a new question. Thanks for your understanding.

    Thanks

    Best Regards


    Starain Chen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, August 1, 2013 12:04 PM
    Moderator