Imports System.Data
Imports MySql.Data.MySqlClient
Public Class Form1
Dim objConn As MySqlConnection
Dim objCmd As MySqlCommand
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim strConnString As String
strConnString = "Server=localhost;User Id=root; Password=1234; Database=csnu; Pooling=false"
objConn = New MySqlConnection(strConnString)
objConn.Open()
BindData()
End Sub
Sub BindData()
Dim strSQL As String
Dim i As Integer
strSQL = "SELECT * FROM tbcsname"
Dim dtReader As MySqlDataReader
objCmd = New MySqlCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
Me.Label1.Text = "<b>Table name have " & dtReader.FieldCount & " Fields</b>"
For i = 0 To dtReader.FieldCount - 1
Me.Label1.Text = Me.Label1.Text & "<br>" & dtReader.GetName(i)
Next
dtReader.Close()
dtReader = Nothing
End Sub
Sub Page_UnLoad()
objConn.Close()
objConn = Nothing
End Sub
End Class
Sub BindData()
Dim strSQL As String
Dim i As Integer
strSQL = "SELECT * FROM tbcsname"
Dim dtReader As MySqlDataReader
objCmd = New MySqlCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
Me.Label1.Text = "<b>Table name have " & dtReader.FieldCount & " Fields</b>"
For i = 0 To dtReader.FieldCount - 1
Me.Label1.Text = Me.Label1.Text & "<br>" & dtReader.GetName(i)
Next
dtReader.Close()
dtReader = Nothing
End Sub
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim connetionString As String
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
Dim sqlQ As String
connetionString = "Data Source=PC-WAT\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"
sqlQ = "Select * from Customers ORDER BY CustomerID"
sqlConn = New SqlConnection(connetionString)
Try
sqlConn.Open()
sqlCmd = New SqlCommand(sqlQ, sqlConn)
Dim sqlReader As SqlDataReader = sqlCmd.ExecuteReader()
Dim i As Integer
For i = 0 To sqlReader.FieldCount - 1
Me.Label1.Text = Me.Label1.Text & sqlReader.GetName(i) & vbCrLf
Next
sqlReader.Close()
sqlCmd.Dispose()
sqlConn.Close()
Catch ex As Exception
MsgBox("Can not open connection ! ")
End Try
End Sub
End Class