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

How to bind a datagrid with the records of a recordsource through coding ??

P: 60
How i can bind the datagrid with the record that are present in a recordsource through programming?

one more thing is that the no of record present in the recordsource may vary according the users input.
TIA

regards
vishwas
Sep 18 '07 #1
Share this Question
Share on Google+
12 Replies


debasisdas
Expert 5K+
P: 8,127
if u are using ADO data control then
try this

Expand|Select|Wrap|Line Numbers
  1. Set DataGrid1.DataSource = Adodc1
Sep 18 '07 #2

P: 60
no i am not using the adodc to connect.

i have the following connection string to connect to the database.

ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=D:\feemgmt.mdb;" & _
"Persist Security Info=False"
Set con = New ADODB.Connection
con.ConnectionString = ConnString
con.Open ConnString


so what can i do to to bind a datagrid with the records of a recordsource through coding.

plz help its urgent

TIA
with best regards
vishwas
Sep 18 '07 #3

P: 60
no i am not using the adodc to connect.

i have the following connection string to connect to the database.

ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=D:\feemgmt.mdb;" & _
"Persist Security Info=False"
Set con = New ADODB.Connection
con.ConnectionString = ConnString
con.Open ConnString


so what can i do to to bind a datagrid with the records of a recordsource through coding.

plz help its urgent

TIA
with best regards
vishwas


is there anybody who can help me ????
Sep 18 '07 #4

P: 60
i want to know about the working of a datagrid control

can anybody help me?

TIA

regards
vishwas
Sep 18 '07 #5

QVeen72
Expert 100+
P: 1,445
Hi,

Check This Code:

Expand|Select|Wrap|Line Numbers
  1. Dim RST As New ADODB.Recordset
  2. Set RST = Nothing
  3. RST.CursorLocation = adUseClient
  4. RST.Open "Select * From MyTable", Conn, adOpenStatic, adLockReadOnly
  5. Set DataGrid1.DataSource = RST
  6.  

Regards
Veena
Sep 18 '07 #6

P: 60
Hi,

Check This Code:

Expand|Select|Wrap|Line Numbers
  1. Dim RST As New ADODB.Recordset
  2. Set RST = Nothing
  3. RST.CursorLocation = adUseClient
  4. RST.Open "Select * From MyTable", Conn, adOpenStatic, adLockReadOnly
  5. Set DataGrid1.DataSource = RST
  6.  

Regards
Veena
nothing is displayed in the datagrid by this code.
there comes the blank datagrid control
Sep 18 '07 #7

QVeen72
Expert 100+
P: 1,445
Hi,

It happens when, u have done any Binding at Design time/FormLoad to a datacontrol/Environment , then u have to remove that. Check This :

Expand|Select|Wrap|Line Numbers
  1.     Dim RST As New ADODB.Recordset
  2.     Set RST = Nothing
  3.     RST.CursorLocation = adUseClient
  4.     RST.Open "Select * From MyTable", Conn, adOpenStatic, adLockReadOnly
  5.     With DataGrid1
  6.         .DataMember = ""
  7.         Set .DataSource = RST
  8.         .Refresh
  9.     End With
  10.  

REgards
Veena
Sep 18 '07 #8

P: 60
Hi,

It happens when, u have done any Binding at Design time/FormLoad to a datacontrol/Environment , then u have to remove that. Check This :

Expand|Select|Wrap|Line Numbers
  1.     Dim RST As New ADODB.Recordset
  2.     Set RST = Nothing
  3.     RST.CursorLocation = adUseClient
  4.     RST.Open "Select * From MyTable", Conn, adOpenStatic, adLockReadOnly
  5.     With DataGrid1
  6.         .DataMember = ""
  7.         Set .DataSource = RST
  8.         .Refresh
  9.     End With
  10.  

REgards
Veena
thanks a lot
but the result is the same,
datagrid comes empty
here is my code

Dim rs As New ADODB.Recordset
Set rs = Nothing
rs.CursorLocation = adUseClient
rs.Open "SELECT date,session from accounts where std_id= '" & txtSearchRoll.Text & "';", con, adOpenStatic, adLockReadOnly

frmShowSearchId.DataGrid1.DataMember = ""
Set frmShowSearchId.DataGrid1.DataSource = rs
frmShowSearchId.DataGrid1.Refresh

frmShowSearchId.Show


what can be the cause???

TIA
regards
vishwas
Sep 18 '07 #9

P: 60
thanks a lot
but the result is the same,
datagrid comes empty
here is my code

Dim rs As New ADODB.Recordset
Set rs = Nothing
rs.CursorLocation = adUseClient
rs.Open "SELECT date,session from accounts where std_id= '" & txtSearchRoll.Text & "';", con, adOpenStatic, adLockReadOnly

frmShowSearchId.DataGrid1.DataMember = ""
Set frmShowSearchId.DataGrid1.DataSource = rs
frmShowSearchId.DataGrid1.Refresh

frmShowSearchId.Show


what can be the cause???

TIA
regards
vishwas

is there any body who can help me ?????
Sep 19 '07 #10

hariharanmca
100+
P: 1,977
No one is here to work your problem.
Try to solve your self then; post your query.
You have to try your best.
Sep 19 '07 #11

QVeen72
Expert 100+
P: 1,445
thanks a lot
but the result is the same,
datagrid comes empty
here is my code

Dim rs As New ADODB.Recordset
Set rs = Nothing
rs.CursorLocation = adUseClient
rs.Open "SELECT date,session from accounts where std_id= '" & txtSearchRoll.Text & "';", con, adOpenStatic, adLockReadOnly

frmShowSearchId.DataGrid1.DataMember = ""
Set frmShowSearchId.DataGrid1.DataSource = rs
frmShowSearchId.DataGrid1.Refresh

frmShowSearchId.Show


what can be the cause???

TIA
regards
vishwas
Hi ,

Write the above code of populating the DataGrid in Form_Load event of frmShowSearchID, not the calling form. thats bcoz, u may have declared the RST as local variable, and it may be out of scope for showing Form.

REgards
Veena
Sep 20 '07 #12

jrtox
P: 89
is there any body who can help me ?????
Hi,

1. Try to Check your "RS"and "Con" if its declared as a global variable.
2. Check if your SQL statement is correct, use SQL builder if it is right.
3. Below is my way to retrive, Save, Update, data from my databse.


'Paste it everywhere as long as its trigger an action, eg in the command button, or during form_load.

sql = "SELECT * FROM Supplier WHERE Name='" & ComboBoxSupplier.Text & "'"
OpenDB (sql)
Set FormName.datagridName.datasource = RS


' Below are Coding in the my Module, Paste it there.

Function OpenDB(sql As String)

Connect

If RS.State = 1 Then
RS.Close
End If

RS.CursorLocation = adUseClient
RS.Open sql, CONN, adOpenDynamic, adLockOptimistic

End Function

'----------

'---------------
Function Connect()

Dim ESQL As String

Set CONN = New ADODB.Connection
If CONN.State = 1 Then
CONN.Close
End If

MSDatabase = App.Path & ("\DBase\datacaddtech.mdb")'Edit with your Database name and location.

ESQL = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MSDatabase & ";Persist Security Info=False"
CONN.Open (ESQL), , , 0


End Function


Regards.
Sep 27 '07 #13

Post your reply

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