Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

Just a quick question about the best way to display data from a SQL query on a form.

 

The following code works fine and lists the records in a listbox, but what I would like to do is display the data in a datagrid or flexigrid, but I have not been able to work out how to do it.

 

Can anyone point me in the right direction.

 

Thanks in advance for any help

 

Slim

 

     
       Dim conA As New Odbc.OdbcConnection
       Dim strSql As String = "select * from product"

       conA.ConnectionString = "DSN=" & txtDsn.Text & ";Password=" & txtPassword.Text & ";User ID=" & txtUsername.Text
       conA.Open()

       Dim mycommand As New OdbcCommand(strSql, conA)
       Dim myODBCreader As OdbcDataReader = mycommand.ExecuteReader

       While myODBCreader.Read
           ListBox1.Items.Add(myODBCreader("Bin"))

       End While
       conA.Close()
       myODBCreader.Close()
       mycommand.Dispose()

Posted

If your application is a windows application, then you have to use a datatable instead of a datareader, but if its a web application you can use this

 

DataGrid1.DataSource=myODBCreader

DataGrid1.DataBind()

Proudly a Palestinian

Microsoft ASP.NET MVP

My Blog: wessamzeidan.net

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...