Add record problems

Nile Hadwards

New Member
try<BR> {<BR> string strConnection = ConnectionString();<BR> OleDbConnection objConnection = new OleDbConnection(strConnection);<BR> <BR> string strAddEmployeeSQL = "SELECT * FROM OrgEmployee";<BR> DataSet objDataSet = new DataSet();<BR> OleDbDataAdapter objAdapter = new OleDbDataAdapter(strAddEmployeeSQL, objConnection);<BR> objAdapter.Fill(objDataSet, "OrgEmployee");<BR> <BR> DataTable objTable;<BR> DataRow objNewRow;<BR> <BR> objTable = objDataSet.Tables["OrgEmployee"];<BR> objNewRow = objTable.NewRow();<BR> objNewRow["FEID"] = Request.Cookies["PayOut"]["FEID"];<BR> objNewRow["SSN"] = Request.Form["SSN"];<BR> objNewRow["LName"] = Request.Form["LastName"];<BR> objNewRow["FName"] = Request.Form["FirstName"];<BR> objNewRow["MName"] = Request.Form["MiddleName"];<BR> objNewRow["EID"] = Request.Form["EmployeeID"];<BR> objNewRow["Dept"] = Request.Form["Department"];<BR> objNewRow["JobCode"] = Request.Form["JobClass"];<BR> objNewRow["Address1"] = Request.Form["Address"];<BR> objNewRow["Address2"] = Request.Form["Address2"];<BR> objNewRow["City"] = Request.Form["City"];<BR> objNewRow["ST"] = Request.Form["State"];<BR> objNewRow["Zip"] = Request.Form["Zip"];<BR> objNewRow["Country"] = Request.Form["Country"];<BR> objNewRow["HomePhone"] = Request.Form["HomePhone"];<BR> objNewRow["WorkPhone"] = Request.Form["WorkPhone"];<BR> objNewRow["Ext"] = Request.Form["WorkPhoneExt"];<BR> objNewRow["EMail"] = Request.Form["EMail"];<BR> objNewRow["Location"] = Request.Form["Location"];<BR> objNewRow["BirthDt"] = Convert.ToDateTime(Request.Form["DateofBirth"]);<BR> objNewRow["HireDt"] = Convert.ToDateTime(Request.Form["HireDate"]);<BR> objNewRow["AnnDt1"] = Convert.ToDateTime(Request.Form["AnniversaryDate1"]);<BR> objNewRow["AnnDt2"] = Convert.ToDateTime(Request.Form["AnniversaryDate2"]);<BR> objNewRow["AnnDt3"] = Convert.ToDateTime(Request.Form["AnniversaryDate3"]);<BR> objNewRow["AnnDt4"] = Convert.ToDateTime(Request.Form["AnniversaryDate4"]);<BR> objNewRow["AnnDt5"] = Convert.ToDateTime(Request.Form["AnniversaryDate5"]);<BR> objNewRow["TermDt"] = Convert.ToDateTime(Request.Form["TerminationDate"]);<BR> objNewRow["Vacation"] = Convert.ToInt32(Request.Form["VacationLeave"]);<BR> objNewRow["Sick"] = Convert.ToInt32(Request.Form["SickLeave"]);<BR> <BR> <BR> if (Request.Form["SalaryPer"] == "Year")<BR> {<BR> objNewRow["Salary"] = Convert.ToDecimal(Request.Form["Salary"]);<BR> objNewRow["PeriodRate"] = Convert.ToDecimal(0);<BR> objNewRow["HourRate"] = Convert.ToDecimal(Request.Form["Salary"]) / Convert.ToDecimal(2080);<BR> }<BR> <BR> <BR> objNewRow["OTRate"] = Request.Form["OTRate"];<BR> objNewRow["PayFreq"] = Request.Form["PayFrequency"];<BR> objNewRow["MStat"] = Request.Form["MaritalStatus"];<BR> objNewRow["Deductions"] = Convert.ToInt32(Request.Form["ClaimedDeductions"]);<BR> objNewRow["AddWH"] = Convert.ToDecimal(Request.Form["Extrawithholding"]);<BR> objNewRow["Route"] = Request.Form["RouteNumber"];<BR> objNewRow["Account"] = Request.Form["BankAccount"];<BR> objNewRow["SupvID"] = Request.Form["Supervisor"];<BR> objNewRow["Spouse"] = Request.Form["Spouse"];<BR> objNewRow["EmergContact"] = Request.Form["EmergencyContact"];<BR> objNewRow["EmergPhone"] = Request.Form["EmergencyPhone"];<BR> objNewRow["EmergExt"] = Request.Form["EmergencyPhoneExt"];<BR> objNewRow["UserID"] = Request.Form["UserName"];<BR> objNewRow["Password"] = Request.Form["Password1"];<BR> objNewRow["AddDt"] = DateTime.Now.ToString("d");<BR> objNewRow["UpdDt"] = DateTime.Now.ToString("d");<BR> objNewRow["UID"] = Request.Cookies["PayOut"]["FEID"];<BR> objTable.Rows.Add(objNewRow);<BR> <BR> OleDbCommandBuilder objBuilder = new OleDbCommandBuilder(objAdapter);<BR> objAdapter.UpdateCommand = objBuilder.GetUpdateCommand();<BR> objAdapter.InsertCommand = objBuilder.GetInsertCommand();<BR> objAdapter.DeleteCommand = objBuilder.GetDeleteCommand();<BR> objAdapter.Update(objDataSet, "OrgEmployee");<BR> <BR> Response.Redirect("OrgEmpRecords.asp?message=Employee Added");<BR> }<BR> catch(OleDbException objError)<BR> {<BR> PageErrors.Text += "<B>There are Errors on the page:</B>";<BR> PageErrors.Text += "<BR><B>Message:</B> " + objError.Message;<BR> PageErrors.Text += "<BR><B>Source:</B> " + objError.Source;<BR> PageErrors.Text += "<BR><B>InnerException:</B> " + objError.InnerException;<BR> PageErrors.Text += "<BR><B>ErrorCode:</B> " + objError.ErrorCode;<BR> PageErrors.Text += "<BR><B>Errors:</B> " + objError.Errors; <BR> }<BR><BR><BR><BR>With this code I get ERRORS any help?<BR>ThanksWhat errors?Message: Syntax error in INSERT INTO statement.<BR>Source: Microsoft JET Database Engine<BR>InnerException: <BR>ErrorCode: -2147217900<BR>Errors: System.Data.OleDb.OleDbErrorCollectionI had this problem a while back and it drove me crazy. The INSERT statement I was using WAS CORRECT, but I kept crashing.<BR><BR>What was really odd was that my code ran fine in the Beta version of the SDK, but crashed with the 1.0.<BR><BR>I finally tracked it down to an illegal use of a reserved word as the name of one of my fields (either in the source database or the dataset). I went back and added an r prefix to the name of each of my fields and the problem went away.<BR><BR>DotNet is too new to know all the obscure reserved or keywords, so it may be difficult to find the actual offending word.<BR><BR>adding the prefix to each field name may be worth a try.<BR><BR>Good luck,<BR><BR>Tom T
 
Back
Top