bind to data grid

  • Thread starter Thread starter gordon
  • Start date Start date
G

gordon

Hi

I have some standard text book type examples of oleDB connections and
routines that populate a list box with data with a query on an Access
database.

What I would like to do is to use a datagrid view instead as the information
in the listbox is very unattractive.

would anyone be kind enough to share some code that can use the result of
the select statement in a datagrid view?

Thansk in advance

doug
 
Function getProductDetails() As System.data.DataSet

Dim connstr As String = "server=(local); user id='sa'; password='hello';
Database='MyDatabase'"

Dim sqlconn As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(connstr)

Dim querystr As String = "select * From ProductDetails"

Dim mycommand As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(querystr, sqlconn)

Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter = New
System.Data.SqlClient.SqlDataAdapter(mycommand)

Dim dataset As System.data.DataSet = New System.data.DataSet

Try

If sqlconn.State = ConnectionState.Closed Then

sqlconn.Open()

End If

dataAdapter.Fill(dataset, "ProductDetails")

Return dataset

Catch ex As Exception

Label1.Text = "Error in retrieving Products Details!"

End Try

End Function

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

'Put user code to initialize the page here

If Not Page.IsPostBack Then

ProductDetails.DataSource = getProductDetails() (ProductDetails is my Id
of my datagrid)

ProductDetails.DataBind()

End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top