Showing posts with label code samle in dot net. Show all posts
Showing posts with label code samle in dot net. Show all posts

Wednesday, August 13, 2008

Code Samples (Select Command)

Select Command
Open a new Web Forms page, add a Button control to it an paste the following code.
Imports System.Data.OleDb
'namespace to be imported

Public Class WebForm5 Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
#End Region

Dim myConn As OleDbConnection
Dim myComm As OleDbCommand
Dim dr As OleDbDataReader
Private Sub Select_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles Select.Click
Try
myConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;_
Data Source=C:\sandeep\books.mdb;")
myConn.Open()
myComm = New OleDbCommand("Select* from Table1", myConn)
dr = myComm.ExecuteReader
Do While dr.Read
'reading from the datareader
Response.Write(dr(0) & " ")
Response.Write(dr(1) & " ")
Response.Write(dr(2) & "
")
'displaying data from the table
'html break is used to display data in a tabular format
Loop
Catch
End Try
End Sub
End Class