Monday, August 16, 2010

How to populate records on datagrid in vb6 from sql server?

it is basically the same as any unbound or bound control in


vb6 using an ADODB.Connection object. the difference is that


you use the sql server connection string. check for the right


connection string at connectionstring.com





this code below will work if you have successfully opened


an unbound ADODB.Recordset. In this example, I named the


unbound recordset as rsTable:





Set Datagrid1.Datasource = rsTable





yet, to make it work, you have to declare it to the References


in Project%26gt;References, then look for the Microsoft Active X


objects 2.0 then check it. if the code below will be


autocomplete, then it will be fine:





Dim CNN as New ADODB.Connection


Dim rsTable as New ADODB.Recordset





Open the connection by:





CNN.Cursorlocation = adUseClient


CNN.Open ';Connection String Here';





Then open your recordset by:





rsTable.Open ';SQL Query Here';, CNN





Then the last thing:





Set Datagrid1.Datasource = rsTable

No comments:

Post a Comment