Neoview ODBC Drivers Manual (R2.5)

Sample Application Code Using ODBC .NET Data Provider
To use the ODBC .NET Data Provider, the application must import the System.Data.Odbc
namespace. For example,
Visual Basic imports System.Data.Odbc
C++ uses namespace System::Data
C# uses System.Data.Odbc
The following source code samples demonstrate setting up (tear down) the connection to the
data source.
Visual Basic
Dim connString As String = "DSN=neo_datasrc;UID=userid,PWD=passWd"
Dim myConn As New OdbcConnection(connString)
...
myConn.open()
myConn.close()
C#
OdbcConnection myConn =
new OdbcConnection(DSN=neo_datasrc,UID=userid;PWD=passwd");
myConn.open();
myConn.close();
After the connection to the data source is established, you can use the OdbcCommand interface
to perform various SQL statements. These source code samples demonstrate selecting data from
the data source:
Visual Basic
Dim myCommand As OdbcCommand =
New OdbcCommand("SELECT * FROM Customers WHERE CustomerID = ?", myConn)
Dim myParamCollection As OdbcParameterCollection = myCommand.Parameters
Dim myNewParameter As OdbcParameter =
myParamCollection.Add("CustoemrID", OdbcType.VarChar, 5, "CustomerID")
C#
OdbcCommand myCommand =
new OdbcCommand("SELECT * FROM Customers WHERE CustomerID = ?", myConn);
OdbcParameterCollection myParamColelction = myCommand.Parameters;
OdbcParameter myNewParameter =
myParamCollection.Add("CustomerID", OdbcType. VarChar, 5, "CustomerID");
These source code samples demonstrate inserting data into a data source:
Visual Basic
Dim myCommand =
New OdbcCommand("insert into empl_info values ('39','Klaus', 'Saffert', 3200, 100, 75000.00, 'new')",
myConn)
myCommand.ExecuteNonQuery()
C#
String insertRec="insert into empl_info values ('39','Klaus','Saffert', 3200, 100, 75000.00, 'new')";
OdbcCommand myCommand = new OdbcCommand(insertRec,myConn);
myCommand.ExecuteNonQuery();
56 Accessing Neoview SQL Data From Microsoft ODBC .NET Data Provider