I am working with a datagrid control. I want to fetch the record onto the datagrid but whenever i try to do , it gives an eror message "Rowset Not Available" Need help Urgent. The code is Dim con As ADODB.Connection Dim rs As ADODB.Recordset Private Sub Form_Load() Set con = New ADODB.Connection Set rs = New ADODB.Recordset con.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=test;Data Source=SOFTWARE" con.Open rs.Open "select * from images", con, adOpenDynamic, adLockOptimistic DataGrid1.Columns(0).DataField = rs.Fields(0) // the above written line does not show me any records in the datagrid // End Sub
your datagrid control needs to be bound to a datasource - have you set values for the .datasource and .datamember properties of the datagrid control?
whenever i try so, it gives me an error reading Method or datamember not found at datagrid1.datasource what i did is rs.open "select * from <tablename>",connectionobject,,, datagrid1.datasource=rs where rs my recordset which has already fetched the records
you cannot assign the datasource property by simply using the "=" operator since the datasource property will need to be an object. use: set datagrid1.datasource = rs try the following - i've confirmed on my laptop that it works **************************** Set con = New ADODB.Connection Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient con.ConnectionString = <YOUR CONNECTION STRING> con.Open rs.Open <YOUR SELECT STATEMENT>, con, adOpenDynamic, adLockOptimistic rs.MoveFirst Set datagrid1.DataSource = rs
rs = recordset object cursorlocation = location of the cursor adUseClient = a vb keyword that indicates the cursor should be created on the client machine instead of the server machine when you specify that the cursor should be on the client machine, all the records retrieved from the server based on the sql select statement is stored in an object locally. this allows faster querying and manipulation of the records in vb. downside is that to commit everything back to the server takes longer...
HI Can anybody tell me how change the background color of a particular row in datagrid needed urgently
Go to your open event and take out the adOpenDynamic statement and make it either asOpenKeyset which I know works or adOpenStatic, and keep the rest of the code the same rsData5.OpenSQL, cn, adOpenKeyset, adLockPessimistic You will have it working in a sec