I am trying to add a new word from a textbox into a table:
private void addAnswer_Click(object sender, EventArgs e)
{
    // Get a new row from the data table
    myDataTable.NewRow();
    DataRow Row1 = new DataRow();
    Row1["Word"] = QuizAnswer.Text;
    myDataTable.Rows.Add(Row1);
    // Locate the newly added row
    currentRecord = myDataTable.Rows.IndexOf(Row1);
    DisplayRow(currentRecord);
    // Commit changes to the database
    UpdateDB();
    myAdapter.Fill(myDataTable);
}
However it is giving me this strange error:
Error 1 'System.Data.DataRow.DataRow(System.Data.DataRowBuilder)' is inaccessible due to its protection level
As the error is trying to tell you, you cannot create a new DataRow() yourself.
Instead, you need to call table.NewRow(), and use the returned row.
You need to create a new DataRow as such:
DataRow dr = dt.NewRow();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With