'System.Data.DataRow.DataRow (System.Data.DataRowBuilder)' is unavailable due to its level of protection

I am trying to add a new word from a text field to 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, this gives me this strange error:

Error 1 'System.Data.DataRow.DataRow (System.Data.DowRowBuilder)' is unavailable due to protection level

+8
c # datatable
source share
2 answers

As you try to say about the error, you cannot create new DataRow() yourself.

Instead, you need to call table.NewRow() and use the returned row.

+34
source share

You need to create a new DataRow as such:

 DataRow dr = dt.NewRow(); 
+5
source share

All Articles