Thursday, March 4, 2010

Reading Data From DataBase

Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient


Public Class MainForm

'''
''' Code for retriving the data from DataBAse Using Sqlserver
'''

'''
'''
'''
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim cn As SqlConnection
Dim cm As SqlCommand
Dim cmdString As String
cmdString = "select compony_Name from compony"
cn = New SqlConnection("Data Source=ANJU\SQLEXPRESS;Initial Catalog=Custumer;Integrated Security=True")
cm = New SqlCommand(cmdString, cn)
cn.Open()
Dim myReader As SqlDataReader

myReader = cm.ExecuteReader(CommandBehavior.CloseConnection)

While myReader.Read()

ListBox1.Items.Add(myReader("compony_Name").ToString)

End While
End Sub
End Class

No comments:

Post a Comment