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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to MS Access using C#

Status
Not open for further replies.

liamba

Technical User
Jan 6, 2007
21
IE
hi,
im trying to write to a ms access database using c#,however i keep running in to problems.
One is
A field initializer cannot reference the nonstatic field, method, or property 'Register.objConnection'

the other
A field initializer cannot reference the nonstatic field, method, or property 'Register.objMemberDA'

the code i am using is

OleDbConnection objConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0.....);
OleDbDataAdapter objMemberDA = new OleDbDataAdapter("select * from tblMember", objConnection);
OleDbCommandBuilder objMemberCB = new OleDbCommandBuilder(objMemberDA);
DataSet objDataSet = new DataSet();

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

objRow=objDataSet.Tables.Add("tblMember").NewRow();

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

objDataSet.Tables.Add(objRow);
objMemberDA.Update(objDataSet, "tblMember");}

Thank you for your help
 
I think you would be better off posting in the C# forum:
C# (C sharp): Microsoft Forum
forum732
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top