Hi there I am new to .net and I have put at least 4 hours in to figuring out why i cannot view my results when I run a datagrid in my 2010 visual studio WPF application.


Also, it looks like it is only filling one record in the datagrid. Any ideas?

Dim cnn As SqlConnection
Dim connectionString As String


connectionString = "Integrated Security=SSPI;Initial Catalog=TestDb;Data Source=" & Environment.MachineName.ToString
cnn = New SqlConnection(connectionString)
cnn.Open()
Dim sql = "SELECT * FROM address "


Dim dscmd As New SqlDataAdapter(sql, cnn)
Dim ds As New DataSet
dscmd.Fill(ds)

DataGrid1.Items.Add(ds)

cnn.Close()

hello !
well try this code ,you have some errors in your code , first , you define dataset , but you had not define a table in it , 2nd one datagrid.items.add(ds) , this is wrong way , if you want to populate the grid then use datasource property , here is a code , hope this will solve your prob

try
dim con as new sqlconnection("Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;")
'now here i am defining a data adapter
con.open
dim da as new sqldataadapter("select * from table",con)
'now m going to define dataset 
dim ds as new dataset 
'here i create a table in it.
        ds.Tables("table").Clear()
'here i fill that table
        da.Fill(ds, "Table")
'here populate the grid
DataGrid1.datasource = ds.tables("table")
con.close
        Catch ex As Exception
msgbox(err.description)

        End Try

this will solve your prob , :)

Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.