Why do queries that worked in VB6, against an Access Database, not work in ADO.NET. The problem may be the use of reserved words as column names.
Having problems with database column names that worked in VB6, but they are not working in ADO.Net? In VB6 you could use column names such as Module, Object, Property, etc. Using these keywords as database column names did not cause a problem in VB6 with an Access MDB, but in ADO.NET you can get some nasty results. Note the following examples:
| sql = "insert into modules (Module, Object) values('TestModule', 'TestObject')" |
| sql = "select module, object from modules where module = 'TestModule' " |
| Public Sub test() Dim dt As New DataTable Dim da As New SqlDataAdaptor Dim cn As New SqlConnection Dim cmd As New SqlCommand Dim Sql As String ' open your connection ' build the sql sql = "Select * from table where field = '" & value & "' " sql &= "order by field" ' fill the table cmd.CommandText = sql cmd.Connection = cn da = New SqlDataAdaptor(cmd) da.Fill(dt) ' process the datatable results ' now reuse the same datatable ' build the sql sql = "Select * from table2 where field2 = '" & value2 & "' " sql &= "order by field" ' fill the table cmd.CommandText = sql cmd.Connection = cn da = New SqlDataAdaptor(cmd) ' reset the datatable before reusing it dt.Reset() da.Fill(dt) End Sub |