Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

datatable

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

like image 916
zzwyb89 Avatar asked Mar 14 '14 16:03

zzwyb89


2 Answers

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.

like image 183
SLaks Avatar answered Nov 02 '22 11:11

SLaks


You need to create a new DataRow as such:

DataRow dr = dt.NewRow();
like image 21
cal5barton Avatar answered Nov 02 '22 13:11

cal5barton