Monday, August 16, 2010

How do I copy a datareader to a datagrid in VB.NET?

I am using Visual Studio 2005How do I copy a datareader to a datagrid in VB.NET?
You just need to set the datagrid's datasource to the datareader object and then enabled the Databind() method.





Dim myCommand as New SqlCommand(strSQL, myConnection)





'Set the datagrid's datasource to the datareader and databind


myConnection.Open()


dgMyGrid.DataSource = myCommand.ExecuteReader( CommandBehavior.CloseConnection )


dgMyGrid.DataBind()





That is all you should need to do to get it bound to the datagrid control.





Hope it works for you! Enjoy!
  • love myspace
  • myspace girl
  • No comments:

    Post a Comment