VB.Net - Access DB - Adding New Rows

Error when adding the new row to data base

Page 1 of 1

0 Replies - 1859 Views - Last Post: 29 April 2008 - 12:30 PM Rate Topic: -----

#1 jjgonzo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-April 08

VB.Net - Access DB - Adding New Rows

Post icon  Posted 29 April 2008 - 12:30 PM

Hi... I am parsing a text email file, line by line, breaking the line into a db fields and values. Using the builtin data adapter, dataset, and connection.

My db connection is good, I can retrieve test records from the db. The code is as, some of it any way. I put in a TRY / Catch routine and the error sys there is a syntax error in thr " INSERT INTO" statement. I found the statement, generated by VB, it looks OK to me. Any ideas???

Add row code:

DBLoad:
		Dim dsNewRow As DataRow
	  
		dsNewRow = Ds.Tables("Survey").NewRow()

		dsNewRow.Item("WorkArea") = WA
		dsNewRow.Item("Equipment") = EQ
		dsNewRow.Item("Environment") = Environment
		dsNewRow.Item("Instructor") = Instructor
		dsNewRow.Item("Class") = FldClass
		dsNewRow.Item("Day") = FldDay
		dsNewRow.Item("ClassTime") = FldTime
		dsNewRow.Item("InstrGreet") = IG
		dsNewRow.Item("InstrKnow") = IK
		dsNewRow.Item("SubMatter") = SMC
		dsNewRow.Item("SubPres") = SMP
		dsNewRow.Item("AskQ") = AQ
		dsNewRow.Item("Discip") = DIS
		dsNewRow.Item("IndiHelp") = IH
		dsNewRow.Item("InstrComment") = InstrComment
		dsNewRow.Item("Tutoring") = Tutoring
		dsNewRow.Item("TutorQ") = TQ
		dsNewRow.Item("ProgPres") = PR
		dsNewRow.Item("Overall") = OE
		dsNewRow.Item("GenComment") = GenComment

		Ds.Tables("Survey").Rows.Add(dsNewRow)
		Try
			da.Update(Ds, "Survey")

		Catch ex As Exception

			MsgBox(ex.Message)
		Finally

		End Try

		MsgBox("New Record added to the Database")



Insert into code:

'OleDbInsertCommand1
		'
		Me.OleDbInsertCommand1.CommandText = "INSERT INTO Survey(AskQ, Class, ClassTime, Day, Discip, Environment, Equipment, G" & _
		"enComment, IndiHelp, InstrComment, InstrGreet, InstrKnow, Instructor, Overall, P" & _
		"rogPres, SubMatter, SubPres, Tutoring, TutorQ, WorkArea) VALUES (?, ?, ?, ?, ?, " & _
		"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
		Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("AskQ", System.Data.OleDb.OleDbType.SmallInt, 0, "AskQ"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Class", System.Data.OleDb.OleDbType.VarWChar, 50, "Class"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("ClassTime", System.Data.OleDb.OleDbType.VarWChar, 50, "ClassTime"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Day", System.Data.OleDb.OleDbType.VarWChar, 50, "Day"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Discip", System.Data.OleDb.OleDbType.SmallInt, 0, "Discip"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Environment", System.Data.OleDb.OleDbType.VarWChar, 255, "Environment"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Equipment", System.Data.OleDb.OleDbType.SmallInt, 0, "Equipment"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("GenComment", System.Data.OleDb.OleDbType.VarWChar, 255, "GenComment"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("IndiHelp", System.Data.OleDb.OleDbType.SmallInt, 0, "IndiHelp"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("InstrComment", System.Data.OleDb.OleDbType.VarWChar, 255, "InstrComment"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("InstrGreet", System.Data.OleDb.OleDbType.SmallInt, 0, "InstrGreet"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("InstrKnow", System.Data.OleDb.OleDbType.SmallInt, 0, "InstrKnow"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Instructor", System.Data.OleDb.OleDbType.VarWChar, 25, "Instructor"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Overall", System.Data.OleDb.OleDbType.SmallInt, 0, "Overall"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("ProgPres", System.Data.OleDb.OleDbType.SmallInt, 0, "ProgPres"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("SubMatter", System.Data.OleDb.OleDbType.SmallInt, 0, "SubMatter"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("SubPres", System.Data.OleDb.OleDbType.SmallInt, 0, "SubPres"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Tutoring", System.Data.OleDb.OleDbType.VarWChar, 50, "Tutoring"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("TutorQ", System.Data.OleDb.OleDbType.SmallInt, 0, "TutorQ"))
		Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("WorkArea", System.Data.OleDb.OleDbType.SmallInt, 0, "WorkArea"))


'

Is This A Good Question/Topic? 0
  • +

Page 1 of 1