Hi guys,i was having this problem with inserting a record into access database in visualstudio 2010.
here's the problem,here's the code
bridgenumber = TextBox1.Text.ToString() bridgename = TextBox2.Text districtname = ComboBox1.Text sectionname = ComboBox2.Text roadsegmentname = ComboBox3.Text bridgetype = ComboBox4.Text bridgespan1 = TextBox3.Text bridgecondition = ComboBox5.Text acquisitionyear1 = ComboBox6.Text evaluationyear1 = ComboBox7.Text endofdesign1 = ComboBox8.Text bridgeasset1 = Label12.Text Dim str As String Dim conn As OleDbConnection = GetDbConnection() Dim cmd As OleDbCommand str = "INSERT INTO AdigratT (Bridge_Number,Bridge_Name,District_Name,Section_Name,Road_Segment_Name,Bridge_Type,Bridge_Span,Bridge_Condition,Acquisition_Year,Evaluation_Year,End_of_Design_Life_Year,Bridge_Asset_Value) VALUES (" & "'" & bridgenumber & "','" & bridgename & "','" & districtname & "','" & sectionname & "','" & _ roadsegmentname & "','" & bridgetype & "','" & bridgespan1 & "','" & bridgecondition & "','" & acquisitionyear1 & "','" & _ evaluationyear1 & "','" & endofdesign1 & "','" & bridgeasset1 & "')" 'and CInt is used to convert number, to string cmd = New OleDbCommand(str, conn) Dim obj As Object = cmd.ExecuteNonQuery() If Not (obj Is Nothing) Then MsgBox("Record has been inserted sucessfully", vbInformation, "Bridge Asset Management") End If conn.Close() conn.Dispose() conn = Nothing End If filllistview()
When i omitted the fields(Bridge_Number,Bridge_Name...)it works perfect but when i tried to insert the fields an exption is thrown.
"The INSERT INTO statement contains the following unknown field name: 'Bridge_Number'. Make sure you have typed the name correctly, and try the operation again."
Do i just simply not write the field names?