I can't see what is wrong with that. I sometimes use something very similar to fill the DataGridView when I need to display records that I don't need to update.
vb.net Code:
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Nwind.mdb;") Dim SQLString As String = _ "SELECT CustomerID, ContactName " & _ "FROM Customers " & _ "WHERE CustomerID LIKE @CustID " & _ "AND ContactName LIKE @ContName" Dim cmd As New OleDbCommand(SQLString, conn) cmd.Parameters.AddWithValue("@CustID", "%" & Me.TextBox1.Text & "%") cmd.Parameters.AddWithValue("@ContName", "%" & Me.TextBox2.Text & "%") conn.Open() Dim dr As OleDbDataReader = cmd.ExecuteReader() Dim dt As New DataTable() dt.Load(dr) Me.DataGridView1.DataSource = dt dr.Close() conn.Close()
So this populates the DataGridView with the correct amount of rows, but doesn't actually put any values in the cells?




Reply With Quote