Data Grid Simple Question
hi all.
im using this code for displaying data in Data Grid
Code:
Public Sub LoadData()
Dim database_file As String
database_file = App.Path & "\db1.mdb"
Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & database_file & ";"
Adodc1.RecordSource = "SELECT * FROM table1"
Set DataGrid1.DataSource = Adodc1
DataGrid1.Caption = "View Data"
End Sub
please tell me is it neccesary to use SQL statement for displaying data in Data Grid.
Can i Display the data in the data grid using code below?
Code:
Set Cn = New ADODB.Connection
Cn.Provider = "Microsoft.Jet.OLEDB.4.0"
Cn.ConnectionString = App.Path & "\db1.mdb"
Cn.Open
Set Rs = New ADODB.Recordset
Rs.Open "Table1", Cn, adOpenDynamic, adLockOptimistic, adCmdTable
if yes please tell me what line i have to add into this code
Re: Data Grid Simple Question
I don't understand how could you get some data without a query?
I would use the 2nd approach (RecordSet) no matter what (of course, it needs some work). Check this to see why.
Re: Data Grid Simple Question
If your asking if you can use a DataGrid without an ADODC, the answer is yes.
The cursor location needs to be as Client
Code:
con1.CursorLocation = adUseClient
then set the grid datasource property like this
Code:
Set DataGrid1.DataSource = Rs
DataGrid1.DataMember = Rs.DataMember
1 Attachment(s)
Re: Data Grid Simple Question
Thank you wes4dbt
this works now my question is in the data grid i can see the Fields name same as in my table. can i change them? so the user will know what is the Real meaning of the field. im uploading my simple example please help me this is very urgent
Re: Data Grid Simple Question
yes i have got its answer by this code
Code:
DataGrid1.Columns(1).Caption = "New Caption"
now please tell me how can i jump to a particular Row in data grid im using this code but it does not jump back to the rows (UP SIDE) which are hidden by scrolling the data grid
Code:
Private Sub Command6_Click()
On Error Resume Next
Do While DataGrid1.SelBookmarks.Count > 0
DataGrid1.SelBookmarks.Remove 0
Loop
DataGrid1.Row = Val(Text4.Text)
DataGrid1.Col = 0
DataGrid1.SelBookmarks.Add Adodc1.Recordset.Bookmark
End Sub
please fix this with the uploaded example of me. please
Re: Data Grid Simple Question
You can also set the column name in the SQL, like
Code:
"select field1 as FirstName, field2 as LastName from table1"
I don't understand what your trying to do with the bookmarks, you don't need them to set the row and col.
Re: Data Grid Simple Question
thank you west4dbt,
i think you are right, i don't need to jump on a particular record. i can use SQL commands for this and this will be enough to work with it.
do you have something to tell me? about data grid or what else i can do with it or what you want me to do with it?
Re: Data Grid Simple Question
I don't know what your trying to accomplish so I can't suggest how to use the grid. I would suggest that you use an ADO recordset instead of an ADODC control for the DataSource, it will be more flexable.
Re: Data Grid Simple Question
i want to allow user to delete , add new record and edit existing records. and i can do all this for now.
Re: Data Grid Simple Question
DataGrid1.Columns(i).Caption = "Your perfered column name"