Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to SQL Server

Status
Not open for further replies.

liamba

Technical User
Jan 6, 2007
21
IE
hi im trying to write to a sql database from textboxes using C#, however i keep getting the following error

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

the code i am using is

public partial class Register : System.Web.UI.Page
{
SqlConnection objConnection;
SqlDataAdapter objMemberDA;
SqlCommandBuilder objMemberCB;

DataSet objDataSet = new DataSet();

protected void Page_Load(object sender, EventArgs e)
{
objConnection = new SqlConnection("Data Source=....;Initial Catalog=....;Integrated Security=True;");
objMemberDA = new SqlDataAdapter("Select * from tblMember", objConnection);
objMemberCB = new SqlCommandBuilder(objMemberDA);
}

public void Retrieve()
{
objDataSet.Clear();
objMemberDA.FillSchema(objDataSet,SchemaType.Source, "tblMember");
objMemberDA.Fill(objDataSet, "tblMember");
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
DataRow objRow = new DataRow();

objRow = objDataSet.Tables["tblMember"].NewRow();

objRow["Name"] = txtMemberName.Text;
objRow["Password"] = txtPassword.Text;
objRow["ConfirmPassword"] = txtConPassword.Text;
objRow["Address1"] = txtAddress1.Text;
objRow["Address2"] = txtAddress2.Text;
objRow["Address3"] = txtAddress3.Text;
objRow["Telephone"] = txtTelephone.Text;
objRow["Mobile"] = txtMobile.Text;

objDataSet.Tables["tblMember"].Rows.Add(objRow);
objMemberDA.Update(objDataSet, "tblMember");

Retrieve();


Any help would be great
Thank You
 
dataRow is a Protected Class, you cannot instantiate a New one.

Changing your code to

Code:
DataRow objRow = objDataSet.Tables["tblMember"].NewRow();

should do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top