Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading a Datagird from ADOBD function

Status
Not open for further replies.

DeeRuff1

Programmer
May 17, 2005
17
US
Hi All,
I am new to the VB.NET world and I was able to get this function working. But there is someone who wants me to fill a grid. Can this be converted into loading a DataGrid.


Public Function openSQLConn(ByRef sServer As Object, ByRef sLogin As Object, ByRef sPASSWORD As Object, ByRef sDatabase As Object) As ADODB

'On Error GoTo errorHandler
Dim strDMISName As String
Dim strDMISNumber As String
Dim sconnstr As String

Dim oconn As ADODB.Connection
oconn = New ADODB.Connection


sconnstr = "driver={SQL Server}; server=" & sServer & "; " & "uid=" & sLogin & "; pwd=" & sPASSWORD & "; database=" & sDatabase
oconn.Open(sconnstr)

Dim rs As ADODB.Recordset
rs = New ADODB.Recordset

Dim fld As ADODB.Field


rs.Open("SELECT * FROM Sites", oconn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly)

If rs.BOF And rs.EOF Then
Exit Function
End If

rs.MoveFirst()

Do While Not rs.EOF

strDMISNumber = rs.Fields("DMIS_ID").Value
strDMISNumber = Microsoft.VisualBasic.Left(strDMISNumber, 4)
strDMISName = rs.Fields("Name").Value
Me.ComboBox1.Items.Add(strDMISNumber & " " & strDMISName)

rs.MoveNext()

Loop

rs.Close()
rs = Nothing

oconn.Close()
oconn = Nothing

Exit Function
 
Have a look at the DataSource property of a DataGrid

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top