Saturday, February 23, 2008

ADO in VB.Net

The beauty of Microsoft technology lies in interoperability. Instead of considering COM, .Net Windows Forms and WPF as seperate technologies I consider it as technologies of same family with excellent interoperatbility.
This blog takes up the issue of working with COM Ado. in .Net.


First of all set a refence to COM Ado by going to Project, Add Reference.







Option Strict Off
Friend Class Form1
Inherits System.Windows.Forms.Form
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub cmdNext_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdNext.Click
rs.MoveNext()
FillData()
End Sub

Private Sub cmdPrvious_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdPrvious.Click
rs.MovePrevious()
FillData()
End Sub

Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
cnn = New ADODB.Connection
cnn.Open("Integrated Security=sspi;Initial Catalog=Northwind;Provider=sqloledb.1")
rs = New ADODB.Recordset
rs.Open("select * from Categories", cnn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
FillData()
End Sub

Private Sub FillData()
txtCategoryName.Text = rs.Fields("CategoryName").Value
txtDescription.Text = rs.Fields("Description").Value
End Sub
End Class

Related article

Using COM Controls in .Net

No comments:

Post a Comment