Grid Problem

eddie

Member
Joined
Apr 21, 2008
Messages
6
Programming Experience
Beginner
This is my piece of code that doesn't work. Nothing is shown in the grid


Dim cmd As New SqlClient.SqlCommand
cmd.CommandText = utakmice.utakmice_SQL

Dim DS As New DataSet()

Dim con As New SqlClient.SqlConnection("Data Source=TNT\SQLEXPRESS;Initial Catalog=kladionica;Integrated Security=True")
Dim adapter As New SqlClient.SqlDataAdapter(cmd)
adapter.SelectCommand.Connection = con
con.Open()

adapter.SelectCommand.CommandText = "select * from parovi"
dgStats.DataSource = adapter
adapter.Fill(DS)
dgStats.Refresh()
con.Close()
 
I am not sure which version of VS you are using. The following code should work with VS2005 and above. For VS2003, you need to change DataGridview to DataGrid. Compare your code with the following. You should find out the answer:

Dim cnnString As String = "Data Source=localhost;Initial Catalog=Pubs;Integrated Security=SSPI;"
Dim adapter As New System.Data.SqlClient.SqlDataAdapter("Select * from Authors", cnnString)
Dim ds As New DataSet
adapter.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
 

Latest posts

Back
Top