By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,644 Members | 2,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,644 IT Pros & Developers. It's quick & easy.

display data to datagrid

P: 44
hey there..
i want to display my data that only has the same "gender" to the datagrid.

Expand|Select|Wrap|Line Numbers
  1.     Dim rs6 As New ADODB.Recordset
  2.  
  3.     With rs6
  4.         .ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Dbname & ";Persist Security Info=False"
  5.         .CursorLocation = adUseClient
  6.         .LockType = adLockOptimistic
  7.         .CursorType = adOpenStatic
  8.         .Source = "SELECT * FROM Data WHERE Gender = '" & comboGender.Text & "'"
  9.         .Open
  10.  
  11.         dgData.Columns(0).Value = .Fields(0).Value
  12.         dgData.Columns(1).Value = .Fields(1).Value
for my code it only show 1 record, though there's 10 records in database.
what code that i miss?
thanks in advance.. =)
Dec 3 '07 #1
Share this Question
Share on Google+
5 Replies


QVeen72
Expert 100+
P: 1,445
hI,

Check This :


Expand|Select|Wrap|Line Numbers
  1.  
  2.     Dim rs6 As New ADODB.Recordset    
  3.     With rs6
  4.         .ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Dbname & ";Persist Security Info=False"
  5.         .CursorLocation = adUseClient
  6.         .LockType = adLockOptimistic
  7.         .CursorType = adOpenStatic
  8.         .Source = "SELECT * FROM Data WHERE Gender = '" & comboGender.Text & "'"
  9.         .Open        
  10.         Set dgData.DataSource = rs6
  11.         dgData.Refresh
  12.      End With
  13.  
Regards
Veena
Dec 3 '07 #2

P: 44
To Mr/Ms. Veena,
thanks for the code,
it works..
but what about if i want to hide other's column?
that's why i using this code before

Expand|Select|Wrap|Line Numbers
  1. dgData.Columns(0).Value = .Fields(0).Value
  2. dgData.Columns(1).Value = .Fields(1).Value
Thanks...
Dec 3 '07 #3

QVeen72
Expert 100+
P: 1,445
Hi,

To Hide 3rd Column:(Index Starts From 0)

Expand|Select|Wrap|Line Numbers
  1. dgData.Columns(2).Width=0
  2.  
Regards
Ms. Veena
Dec 3 '07 #4

P: 44
To Ms.Veena,
forgive me if i still ask the same question
if i want to display only column 0 and 1,
because for column 3 i will add the data myself
so i cant Set dgData.DataSource = rs6 because it displayed whole data

sorry for keeping asking the same question..
thanks in advance..
Dec 3 '07 #5

QVeen72
Expert 100+
P: 1,445
To Ms.Veena,
forgive me if i still ask the same question
if i want to display only column 0 and 1,
because for column 3 i will add the data myself
so i cant Set dgData.DataSource = rs6 because it displayed whole data
Hi,
Either of these commands will Hide the Third Column :

dgData.Columns(2).Visible = False
Or
dgData.Columns(2).Width = 0

And you can very well use :
Set dgData.DataSource = rs6
As Recordset Object has the Column Data,
Onlything here is Physically, the Column is Hidden, (But Underlying Column in datagrid is Intact)

ColumnWidth / Visible has to be done after the "Set" command..

Regards
Veena
Dec 3 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.