Hi
How can i show data in datagrid from sql server database
Hi — short, practical VB6 steps that follow 's ADO suggestion so you can display SQL Server data in a DataGrid. Add a reference to "Microsoft ActiveX Data Objects 2.x Library" (Project -> References) and the "Microsoft DataGrid Control 6.0" (Components). Put this in Form_Load and adjust server/database/table/credentials.
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=SQLOLEDB;Data Source=SERVERNAME;Initial Catalog=DBNAME;Integrated Security=SSPI;"
cn.Open
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM YourTable", cn, adOpenStatic, adLockReadOnly
Set DataGrid1.DataSource = rs
DataGrid1.Refresh
' Cleanup
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing If nothing appears: confirm the ADO reference and DataGrid control are added, verify the connection string (use SERVER\INSTANCE if needed), check SQL auth vs Windows auth, test the same query in Query Analyzer/SSMS, and confirm the table has rows. For large result sets use server-side paging or a filtered query. If you actually need VB.NET instead of VB6, let us know and we can show the ADO.NET/DataGridView pattern. : thanks for the quick reply earlier — this gives a concrete example to try.
Jump to Post— WaltP 2,905Yes
Yes
Hey Walt, bd asked how not can I... :)
bd, see the ado tutorial or use your friends (yahoo, google, ask, answers, bing) to search for vb6 ado tutorial and once you have that under your belt, search for vb6 ado grid...
Good Luck
Hey Walt, bd asked how not can I... :)
Yep. Sorry. I read it too fast. Missed the how
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.