Welcome Guest Search | Active Topics | Sign In | Register

populate a gridview from a database SQL server Options
ivanomonti
Posted: Wednesday, May 21, 2008 7:54:05 AM
Rank: Newbie
Groups: Member

Joined: 5/21/2008
Posts: 7
Using Visual studio 2008 and SQL Server 2005 express

Script in VB for page Default.ascx ... I have trouble populate a grid1, use this script in vb.....

(Forgive English, are italian, not writer good English.)

examples (version demo DessentialObject)

Dim SQLString As String = "SELECT * FROM WM08 WHERE WM08_Attivo = 'Si'"
Dim myConnString As String = "User ID=" & user & ";password=" & pw & ";Initial Catalog=" & dbuser & ";Data Source=" & ipuser & ";"
Dim myConnection As New SqlConnection(myConnString)
Dim myCommand As New SqlCommand(SQLString, myConnection)
'
myConnection.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader()
Dim dt As New DataTable
'
If (myReader.HasRows) Then
dt.Load(myReader)
Grid1.DataSource = dt
End If
myConnection.Close()

End script examples




eo_support
Posted: Wednesday, May 21, 2008 9:03:28 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Check if you have any columns. Our Grid does not automatically generate columns based on the data source:

http://www.essentialobjects.com/ViewDoc.aspx?t=Grid%2fstart.html

You don't really need to use a DataTable. You can directly give myReader to Grid1.DataSource.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.