VB Question

Discussion in 'Programming' started by vijaykoul, Mar 28, 2005.

  1. #1
    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
     
    vijaykoul, Mar 28, 2005 IP
  2. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #2
    your datagrid control needs to be bound to a datasource - have you set values for the .datasource and .datamember properties of the datagrid control?
     
    daboss, Mar 28, 2005 IP
  3. vijaykoul

    vijaykoul Guest

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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
     
    vijaykoul, Mar 28, 2005 IP
  4. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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
     
    daboss, Mar 29, 2005 IP
  5. vijaykoul

    vijaykoul Guest

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    it is really working
    thanx a lot
    but can u tell me what does

    rs.CursorLocation = adUseClient

    do
     
    vijaykoul, Mar 29, 2005 IP
  6. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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...
     
    daboss, Mar 29, 2005 IP
  7. vijaykoul

    vijaykoul Guest

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanx a lot for this guidance
    i was in great need of this
    thax again
     
    vijaykoul, Mar 29, 2005 IP
  8. vijaykoul

    vijaykoul Guest

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    HI

    Can anybody tell me how change the background color of a particular row in datagrid
    needed urgently
     
    vijaykoul, Mar 30, 2005 IP
  9. tzmaxx

    tzmaxx Guest

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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
     
    tzmaxx, Oct 4, 2006 IP