Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting Data from Datagrid

Status
Not open for further replies.

newbie1983

Programmer
Sep 9, 2003
52
GB
I have managed to populate a datagrid with an ado recordset. However i am having problems extracting particular coloumn data from the datagrid. Does anyone know of how this can be achieved?

Kind regards

newbie1983
 
If you have a recordset populating the datagrid, why not just get the data from the recordset directly?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
The recordset contains data of type date e.g 01/04/2004 in a sql server database of data type DateTime. I cant convert using CDate() in visual basic 6 to this data type. Therefore by accessing the data in the datagrid it would be possible to do conversion.
 
Check out the columns collection. For the current row you can examine the content of

DataGrid.Columns(i)

which I think is what your after.
 
I did this today with the DateTime SQL SERVER data type.

I used the CDATE to make my txtdata a date type in order to ADD the data to the DB.

example:

Dim dateVar As Date
dateVar = CDate(txtWhatever.Text)


However, when I read the data from the Recordset, I was able to just read the TimeDate type into a String field.

example:

txtWhatever.Text = RecordSet!datefield


THE REAL PROBLEMS are making sure the text field is in the correct format 4/1/2005 etc.

Does that help?
 
Hi blastingm

thanks for your reply - was very useful, the only problem i have then is to populate a new recordset so that i can assign this to the datagrid so that the selected dates that i want are populated onto this? for example,

datagrid.datasource = Newrecordset

where Newrecordset contains the records with the selected date.

regards

newbie
 
DrJavaJoe and other members helped me with this similar problem.

I wanted to extract all records between two dates (FromDate and To Date fields)of my DataGrid (and also my Recordset)and then print the results onto a DataGrid.

This is the code we came with:

Private Sub GetConnection()
If Cn.State = 0 Then
Dim ConnectionString As String
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\ehicks\Desktop\RESIDENTIAL PROPERTY MANAGER\RPM.mdb;Persist Security Info=False"
Cn.CursorLocation = adUseClient
Cn.Open ConnectionString
End If
End Sub

Private Sub Command1_Click()
Unload RentRoll
Load Rent_Roll_Menu
Rent_Roll_Menu.Show
Load RentRoll
RentRoll.Show
Unload Rent_Roll_Menu
End Sub

Private Sub Command20_Click(Index As Integer)
Load RentRoll_Help
RentRoll_Help.Show
Unload RentRoll
End Sub

Private Sub Form_Load()
'If rs.State = 1 Then
'rs.Close
'End If
'Call GetConnection
'rs.Open
End Sub

Private Sub Command11_Click(Index As Integer)
OpenReport1
End Sub
Private Sub OpenReport1()
Dim rpt As RentRoll2
Set rpt = New RentRoll2
rpt.Display Me.Adodc1.Recordset, vbModal
Set rpt = Nothing
End Sub

Hope it helps! Hiccup
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top