Link to home
Start Free TrialLog in
Avatar of bobydesi
bobydesi

asked on

displaying frational values in datagrid from a database table using VB6

how do i get fractional values from a database table in VB 6?
I have database table *.dbf that i open using following code

Dim strCnn As String
strCnn = "Provider=MSDASQL.1;" & _
"DBQ=C:\.......;DefaultDir=C:\......;" & _
"Driver={Microsoft dBase Driver (*.dbf)};" & _
"UID=admin;UserCommitSync=Yes;"

Set cnn1 = New ADODB.Connection
cnn1.Open strCnn

rsR.Open "R.DBF", cnn1, , , adCmdTable

Then I assign the record to datagrid.
everything works except...
1. in some of the data field i have fractional values like 1 1/2 .. 4 3/4 etc.
the datagrid displays 1+.. 4+ the fractional values are not displayed.
2. If i use jet engine and ADODC datacontrol and bind the above field (containing the fractional value) to a textbox , then the data is displayed as it should, 1 1/2 .. 4 3/4 etc.
3. If i open this table in access or foxpro the data is displayed with proper fractions.
4. I tried different drivers jet,foxpro,access etc. to open the tabel but the datagrid NEVER displays the fractional part.
my question is 2 part:
1. what is going on with datagrid ?? what am i doing wrong.
2. ADODC datacontrol works but how do i bind it to datagrid ?? when i try assigning datasource property of datagrid with adodc.recordset i get error.
Thanks in advance.
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Make sure your not declaring the variable an Integer when adding it to the datagrid..dont know all of how you are using your code but this could be the problem.

If there fixed decimals then declare your variable as Currency
Avatar of bobydesi

ASKER

Thanks for your response.
I am ver carefull with matching data types etc.
Here is another bit of information.
1. once i have opened the database table (say tbl.dbf) using various drivers i tried printing with debug.print tbl!fld1 the fld1 contains 9 1/2 but the debug.print prints 9+.
2. if i open tbl.dbf in VisualFoxPRO and browse the table the tbl!fld1 value is displayed as 9 1/2. This means that the VFpro is interpreting the data correctly, however if i use "FoxPro Driver" in the connection string to open tbl.dbf within the VB6 code, the data is displayed as 9+.
I have a feeling it may have to do with some sort of sytem/character code setting, is it possible?
Also my original connection string is:
Dim strCnn As String
strCnn = "Provider=MSDASQL.1;" & _
"DBQ=C:\.......;DefaultDir=C:\......;" & _
"Driver={Microsoft dBase Driver (*.dbf)};" & _
"UID=admin;UserCommitSync=Yes;"
 I tried changing the driver to FoxPro as follows

Dim strCnn As String
strCnn = "Provider=MSDASQL.1;" & _
"DBQ=C:\.......;DefaultDir=C:\......;" & _
"Driver={Microsoft FoxPro Driver (*.dbf)};" & _
"UID=admin;UserCommitSync=Yes;"
 I received a runtime error -2147467259(80004005)
[microsoft][odbc foxpro driver] could not find installable ISAM

All your help is highly appreciated.
 
If your using the datagrid control, have you tried right click on it an choosing properties, then the FORMAT tab, mess around with all the formats you might need to change the format to a string, or some other format.
There a FORMAT called CUSTOM try typeing in something like:

# 1/2
Or you can try something like this

# #/#
Thank you for your responses. May be I should rephrase the question. Here is my problem.
1. I have bunch of database files *.DBF extention that i need to open and access data from a VB 6 program.
2. I have to use datagrid for data display/manipulation as lots of programming effort has been put it. Also i can not use ADODC datacontrol because I don't think it can be easily dynamicaly bound to the datagrid (??? if any one knows how , that can help). I  define my own ADODB recorsets,connection etc. to load and manipulate these tables.
3. The *.dbf files might have been generated by Access,dbase or FoxPro. I don't know and there is no way for me to know. We get these DBF files every day, we process this table and update our giant database.
4. These dbf files have certain fields where it contains fractional data, e.g. 3 1/2, 2 3/4,3,6 etc.
5. if i use jet,dbase etc. dbf drivers then the fractions mentioed in 4. appears as 3+,2+,3,6 respectively. Even when i view this data using Access i get the same result.
6. If i open these tables in FoxPro then data appears as 3 1/2,2 3/4,3,6 etc. These makes me believe that the FoxPro will be a correct driver for these *.dbf data table.
QUESTION:
Can anybody show mw an example of how i can set up the connection string so that the "FoxPro" driver is used to load these table. As i had mentioned earlier. I tried my connection string with "foxpro" driver and got following error
Dim strCnn As String
strCnn = "Provider=MSDASQL.1;" & _
"DBQ=C:\.......;DefaultDir=C:\......;" & _
"Driver={Microsoft dBase Driver (*.dbf)};" & _
"UID=admin;UserCommitSync=Yes;"

Set cnn1 = New ADODB.Connection
cnn1.Open strCnn

' I use the connection as follows to open a record set
Set rsR = New ADODB.Recordset
rsR.CursorType = adOpenKeyset
rsR.LockType = adLockOptimistic
rsR.Open "ESHP.DBF", cnn1, , , adCmdTable
 
'The above works fine, Do you see any problem the way I have used dbase driver. Am I missing something?

 I tried changing the driver to FoxPro as follows

Dim strCnn As String
strCnn = "Provider=MSDASQL.1;" & _
"DBQ=C:\.......;DefaultDir=C:\......;" & _
"Driver={Microsoft FoxPro Driver (*.dbf)};" & _
"UID=admin;UserCommitSync=Yes;"

 I received a runtime error -2147467259(80004005)
[microsoft][odbc foxpro driver] could not find installable ISAM

Hi,
 Thank you for all for your help. After trying a few things i was able to get the fractional parts from the table, I had to use the ODBC driver for my connection object.
strFoxCnn = "Driver={Microsoft Visual FoxPro Driver};" & _
           "SourceType=DBF;" & _
           "SourceDB=C:\mydir;" & _
           "Exclusive=No"
I do not completly understand but FoxPro driver interpretes this *.DBF table correctly as opposed to dbase or jet.
Admin, please close this thread.
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

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