Link to home
Start Free TrialLog in
Avatar of vidyas
vidyas

asked on

Data Grid control returning error constants!

I'm using a data grid control to display elements from a database.

My requirement needs that i populate different data from different tables in the database depending on the menu items i select.

the problem I'm facing is that when i chose a menu item, the records get populated in the data grid control correctly.

if i select a field in the data grid and then chose another menu item that causes the contents of the data grid control to change, i get a message box saying : "The current row is not available"
After i click on "OK", i get the next set of reports correctly listed in the control.

Basically the data is getting populated correctly, the only thing bothering us is the message box each time the data needs to be changed.

Is there a way we could eliminate this message box from appearing?

These are a few findings:
we looked up the MSDN library and found that this message is displayed when the following error constant is returned : dbgNoCurrentRow

The value returned by this is 7008.

however we are unable to find out the reson why this is being logged and how we can avoid this.

Kindly enlighten us.

Thanks,
Avatar of jdhananjay
jdhananjay

hi
 try this
 What u do First time when u assign the datasource to datagrid then it is not giving error Ok. When u select other item from menu and then u assignging the that time do this
set datagrid1.datasource = nothing
datagrid1.clearfields
And then assign ur new recordset to Datagrid.
Good Luch
Bye
Jay
Open the datasource as readonly.
Set Datagrid1.Allowupdate = False.. when in Inquiry mode. Set it back to True if/when you need to update.. <smile>.
Avatar of vidyas

ASKER

checked setting datagrid.datasource to nothing and checked using datagrid1.clearfields.

The message box still turns up, while a field is selected, but does not turn up when no fields are selected.

datasource is opened as "Read_only"

(Thanks for your suggestions)
Any more?
Just give On Error Resume Next as the first statement of the procedure and contnue. U would not get any problems.
Are u writing any event when the data or cell changes in the DataGrid.

Avatar of vidyas

ASKER

Adjusted points from 50 to 65
Avatar of vidyas

ASKER

Cannot try "On Error Resume Next" as i am handling other errors in the same procedure.

Nope, i'm not writing any event when the data changes in the Data Grid.
Send the code
Avatar of vidyas

ASKER

- Here's the code snippet -

 Set DataGrid1.DataSource = Nothing
 DataGrid1.ClearSelCols
 DataGrid1.ClearFields

 conRpt.Open "DSN=tracer"
 conRpt.CursorLocation = adUseClient

 cmd.ActiveConnection = conRpt
 cmd.CommandText = TracerInit.strRptQryName
 cmd.CommandType = adCmdStoredProc

 For i = 1 To TracerInit.nRptParamNum
     Set prm = cmd.CreateParameter(TracerInit.strRptParam(i), adInteger, adParamInput)
    cmd.Parameters.Append prm
    prm.Value = TracerInit.valRptParam(i)
 Next
 Set rsRpt = cmd.Execute
 cmd.cancel
 Set Me.Adodc1.Recordset = rsRpt
 
 Set DataGrid1.DataSource = Adodc1

 '--display block
 '//-To adjust the grid column widths according to the text size
 ReDim lenArray(Me.DataGrid1.Columns.Count)
 '//-LenArray contains the max width of each column
 For Each colItem In Me.DataGrid1.Columns
    lenArray(colItem.ColIndex) = Len(rsRpt.Fields(colItem.ColIndex).Name)
    rsRpt.MoveFirst
    While Not rsRpt.EOF
        ncolLength = Len(CStr(Format(rsRpt(colItem.ColIndex).Value)))
        If lenArray(colItem.ColIndex) < ncolLength Then
            lenArray(colItem.ColIndex) = ncolLength
        End If
        rsRpt.MoveNext
    Wend
    lenArray(colItem.ColIndex) = lenArray(colItem.ColIndex) * 110
    colItem.Width = lenArray(colItem.ColIndex)
    ntotlength = ntotlength + (lenArray(colItem.ColIndex))
 Next
 
hi

Set Me.Adodc1.Recordset = rsRpt  
Set DataGrid1.DataSource = Adodc1

use this

Set DataGrid1.DataSource = rsRpt  

And Use

do until rsRpt.EOF = True
ncolLength = Len(CStr(Format(rsRpt
          (colItem.ColIndex).Value)))
If lenArray(colItem.ColIndex)
                    ncolLength Then
 lenArray(colItem.ColIndex)= ncolLength
End If
   rsRpt.MoveNext
loop

insted of
While Not rsRpt.EOF
  ncolLength = Len(CStr(Format        
    (rsRpt(colItem.ColIndex).Value)))
 If lenArray(colItem.ColIndex)
                     ncolLength Then
 lenArray(colItem.ColIndex)= ncolLength
 End If
     rsRpt.MoveNext
Wend
Avatar of vidyas

ASKER

Edited text of question.
Avatar of vidyas

ASKER

Edited text of question.
Avatar of vidyas

ASKER

Tried using do until instead of while!

Does not work.
Avatar of vidyas

ASKER

Any other answers as yet?
First of all, delete these lines:

Set DataGrid1.DataSource = Nothing
DataGrid1.ClearSelCols
DataGrid1.ClearFields

and down further:

Set DataGrid1.DataSource = Adodc1
 
As the Datagrid is going to get overlayed they are unnecessary.

--------------------------------------
You now have two choices:

1.  If you want to update the ADODC, then change this line to read:

Set Me.Adodc1.Recordset = rsRpt
Me.Adodc1.Refresh

2.  To be honest, you don't need the Adodc1 to accomplish what you want. Change:

Set Me.Adodc1.Recordset = rsRpt

To:

Set DataGrid1.DataSource = rsRpt

and the Datagrid will be updated accordingly.


 
Avatar of vidyas

ASKER

hi wsh2, it still gives the same error.
maybe i need to change the control itself.
No.. I think the control is fine.. <smile>. What I'm now thinking is that you have an unfinished transaction somewhere.. an .addnew or an .edit or a .delete that you have not followed up with an .update. This would cause a record page lock.. and a record unavailable message. Can you check your logic for this? Or.. perhaps somewhere else in your program.. you are accessing a part of the same table where a record page lock is taking place. Mind you, that is only an educated guess.. but I certainly would check that out.

You may also want to check out your CursorTypes. Only a setting of adUseStatic is supported if the CursorLocation property is set to adUseClient. If a provider does not support the requested cursor type, the provider may return another cursor type. Perhaps the quickest way to remedy this would be to change your CursorLocation to adUseServer. By the way, what ODBC provider are you using?

Welp.. give that adUseServer thing a shot.. and see how it works out.. meanwhile, I will (along with the others) give it more thought.. <smile>.
Avatar of vidyas

ASKER

Adjusted points from 65 to 90
Avatar of vidyas

ASKER

Nope, i checked out for unfinished transactions. since i'm doing all updations, additions, deletions through a connection object, i don't think an 'update' is needed - a "con.execute" should suffice.

n reg the adUseServer thing, i tried changing the cursorLocation to adUseServer.. it still gives the error!!

ODBC Driver being used is MS Access,
Thanks.
Avatar of vidyas

ASKER

Folks, now the problem seems to have changed, might give us further insight to the problem.

I changed the database options to open it in "Exclusive Mode" only.

and now the earlier error: "current row not available" has been replaced with this one: "[Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed "

However the message box pops up at the same instances as the previous one, that is, if a field of the grid is selected.

Findings::
Found that this error gets logged possibly by SQLBrowseConnect ,SQLConnect or  SQLDriverConnect

Problem again: I'm *not* using any of the above statements.

I'm only using a connection object to connect to the databse. is this creating problems?

Any clues now to remove this message box?
ASKER CERTIFIED SOLUTION
Avatar of jdhananjay
jdhananjay

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vidyas

ASKER

Would like to give some points to others too, is that possible?

To leave additional points.. just post a question with "FOR <screenname> ONLY" in the question subject.. and assign it the points you feel deserved.
Hi Vidyas
  Thanks for accepting my answer.
If u have any problem contact me on hijai23@yahoo.com.
Good Luck.
Bye
Jay
Avatar of vidyas

ASKER

Thanks a bunch to all those involved!