Hi everyone,
I setup my data grid and I'm filling it using a dataset from code no (see below). I defined all my columns and pointed them to the database fields and it shows just fine in design time. However when I run it the columns are remapped by the dataset showing all the fields instead of the 5 I picked. I can't find anything like Auto Generate fields as in asp .net. If someone can help I would appreciate it.
thanks
-rjp
Code:
Dim myDataSet As New DataSetmyConnection.Open()
strSQL = "SELECT * FROM LstData ORDER BY ID
"myDataAdapter =
New SqlDataAdapter(strSQL, myConnection)myDataAdapter.Fill(mydataset, "Listings")
gridListings.DataSource = myDataSet.Tables("Listings")
myConnection.Close()

Need help... GridView defaults to all records
limelight
Jaros?aw Kowalski
I understand that however heres whats going on - I setup 5 columns out of a table of 7 fields. I'm selecting all the records because I want the other records to populate txtboxes on the form as you move from record to record in the grid so I can't cut down the sql statement. Ok so I have my 5 columns and in design it looks great. When I run the app it plugs in the other 2 fields. Hence this is my problem...
-rjp
Ankit2008
David Hubbard
Roger McKinney
To hide a column, set its width to zero or use MappingType as per this code sample –
Dim strCON As String = "<Connection String>"
Dim strQuery As String = "Select Field1, Field2 from TBL"
Dim DA As SqlDataAdapter = Nothing
Dim DS As DataSet = Nothing
Try
Dim CON As New SqlConnection(strCON)
DA = New SqlDataAdapter(strQuery, CON)
DS = New DataSet
DA.Fill(DS, "TBL")
CON.Close()
Catch ex As Exception
MsgBox("Error")
Me.Close()
Return
End Try
'Here you can HIDE the Column
DS.Tables("TBL").Columns("Field1").ColumnMapping = MappingType.Hidden
'
DataGrid1.DataSource = DS.Tables("TBL")