By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,466 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

bind to data grid

P: n/a
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

Jul 29 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"gordon" <go**********@optusnet.com.auwrote in message
news:44***********************@news.optusnet.com.a u...
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

Jul 31 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.