We are using the Native database of Navison 4 SP1
I am trying to create a connection to the user table in the database by using the N/ODBC connection with VB.Net 2003.
I can create the connection, when i tell VB.net to show me the records -> No problem, i can see them all.
but then i try to select the records of the table and fill it into a dataset.
This doesn't work.
[Code]
Dim MyConn As New OdbcConnection
Dim MyDataAdapter As New OdbcDataAdapter
Dim MyDataset As New Dataset1
MyConn.ConnectionString = "DSN=Navision MBS40Live;UID=harold;PWD=hva1910"
Try
MyConn.Open()
Me.StatusBarPanel1.Text = "Connection open"
Catch ex As Exception
MessageBox.Show("Failed to connect to data source" & vbCrLf & ex.ToString)
Me.StatusBarPanel1.Text = "Connection failed"
End Try
Try
MyDataAdapter.SelectCommand = New OdbcCommand("SELECT * FROM User WHERE Name <> ''", MyConn)
Me.StatusBarPanel1.Text = "Table Selected"
Catch ex As Exception
MessageBox.Show("Failed to Select Table" & vbCrLf & ex.ToString)
Me.StatusBarPanel1.Text = "Failed to select Table"
Exit Sub
End Try
Try
MyDataAdapter.Fill(MyDataset.UsersTable)
Me.StatusBarPanel1.Text = "Dataset filled"
Catch ex As Exception
MessageBox.Show("Failed to Fill Dataset" & vbCrLf & ex.ToString)
Me.StatusBarPanel1.Text = "Failed to Fill Dataset"
Exit Sub
End Try
Try
MyConn.Close()
Me.StatusBarPanel1.Text = "Connection close"
Catch ex As Exception
MessageBox.Show("Failed to close the data source" & vbCrLf & ex.ToString)
Me.StatusBarPanel1.Text = "Connection ???"
Exit Sub
End Try
Try
Me.DataGrid1.DataSource = MyDataset.UsersTable
Catch ex As Exception
MessageBox.Show("Failed set Datagrid Datasource" & vbCrLf & ex.ToString)
Me.StatusBarPanel1.Text = "Failed set Datagrid Datasource"
Exit Sub
End Try
[\Code]
[Error message]
Failed to Fill Dataset
System.Data.Odbc.OdbcException: ERROR [42000] [Simba][SimbaEngine ODBC Driver]SELECT * FROM User<< ??? >> WHERE Name <> ''
ERROR [42000] [Simba][SimbaEngine ODBC Driver]Syntax Error.
at System.Data.Odbc.OdbcConnection.HandleError(HandleRef hrHandle, SQL_HANDLE hType, RETCODE retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method)
at System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Odbc.OdbcCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at NavisionConnection.Form1.ConnectToOdbc() in C:\Documents and Settings\H.vanAarsen\Mijn documenten\Visual Studio Projects\OnderZoek\NavisionConnection\Form1.vb:line 130
[\Error message]
Can anybody tell me what is wrong
Or perhaps send me some code that does work ?
With kind regards,
Harold van Aarsen
0
Comments
My VB is a bit rusty, but shouldn't this line
MyDataAdapter.Fill(MyDataset.UsersTable)
read
MyDataAdapter.Fill(MyDataset("UsersTable"))
Charl
Almost right, you can write it the I do or:
MyDataAdapter.Fill(MyDataset, "UsersTable")
Both work the same way.
Dim MyDataset As New Dataset1
or should it be
Dim MyDataset As New Dataset
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
I use a predifined dataset and just for the ease of it called it DataSet1
solution in C# .net:
now goodluck going from c# -> VB
So far this is working extremely wel for many tables like sales header, sales line, item, customer, ...
But trying to access table 2000000002 User gives the error shown in the start post.
My guess is that the Navision ODBC driver does not like the expression "User"