Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB.NET
Private Sub FLEX1_LOAD()
      DataGridView1.Rows.Clear() 
      Dim strsql As String
      Dim rs2 As ADODB.Recordset
      strsql = "select * from voterlist where AREAID='" & Trim(lblAreaid.Text) & "'"
      rs2 = New ADODB.Recordset
      Call dbconnect2()
      rs2.Open(strsql,conne2,ADODB.CursorTypeEnum.adOpenStatic,ADODB.LockTypeEnum.adLockPessimistic)
      If rs2.RecordCount > 0 Then
       rs2.MoveFirst()
       For I = 0 To rs2.RecordCount - 1
          DataGridView1.Rows.Add(1)
          DataGridView1.Rows(J).Cells(0).Value = J + 1
          DataGridView1.Rows(J).Cells(1).Value =rs2.Fields("ID").Value
          DataGridView1.Rows(J).Cells(2).Value = rs2.Fields("NAM").Value & " " & rs2.Fields("SURNAME").Value & "/" & rs2.Fields("RTYPE").Value & "-" & rs2.Fields("RNAME").Value & " " & rs2.Fields("RSURNAME").Value
          DataGridView1.Rows(J).Cells(3).Value = rs2.Fields("AGE").Value
          J = J + 1
          rs2.MoveNext()
       Next
      End If
      rs2.Close()
      rs2 = Nothing
      conne2.Close()
End Sub


What I have tried:

How to convert recordset to dataset because while 200 more data load to datagridview that after datagrid has been very slow, so i want my code change to load datagrid by dataset but i dont know dataset code how to merge multiple field of database data into one column in datagrid, So please help me...
Posted
Updated 17-Oct-16 18:59pm
v2

1 solution

If I understand the question correctly, modify for example the query to return a concatenated field. For example
SQL
SELECT NAM & ' ' & SURNAME, RNAME ...
FROM ....

As a side note I would recommend dropping the ADODB and using OleDbConnection Class (System.Data.OleDb)[^] instead. Also you could load the data into a DataTable Class (System.Data)[^] which probably would make the data handling far more easier.

Also you seem to concatenate values from user interface objects directly to the SQL statement. This leaves you open to SQL injections so it should be fixed. With OLEDB you can use OleDbParameter Class (System.Data.OleDb)[^]
 
Share this answer
 
Comments
Member 10469183 18-Oct-16 1:47am    
Thank you, its working by oleDb method, but here again a question- if result of oledb 'SEX'= 1 Then how to auto view in datagrid 'SEX'="M" at a time of loading datagridview.
Wendelius 18-Oct-16 2:18am    
If you want to do formatting on the grid, have a look at DataGridView.CellFormatting Event (System.Windows.Forms)[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900