[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Bill

11/14/2002 4:29:00 AM


I'm new to vb.net and most of my VB coding has been in Access 97 using
DAO. I'm trying to connect to an ACT .dbf file (which I can do easily
in Access 97 using the dBase driver) When I run the following code it
breaks at the "Fill" command. The form opens up OK, but when I click
the button to test the "Fill" statement, I get an unspecific system
error...

Can someone help?

TIA
Bill
____________________________________________
Public Class Form2
Inherits System.Windows.Forms.Form

Dim objConnection2 As New
Microsoft.Data.Odbc.OdbcConnection("Driver = (Microsoft dBase Driver
(*.dbf));DBQ=f:\temp\DseekCI.dbf")
Dim objContactDA2 As New
Microsoft.Data.Odbc.OdbcDataAdapter("Select * from DSeekCI",
objConnection2)
Dim objContactCB2 As New
Microsoft.Data.Odbc.OdbcCommandBuilder(objContactDA2)

Dim objDataSet2 As New DataSet()


(Windows Form Designer Code


Private Sub btnRetrieve_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnRetrieve2.Click
Dim strCurrentID As String
Dim i As Long
objDataSet2.Clear()
objContactDA2.Fill(objDataSet2, "DSeekCI")
End Sub
8 Answers

(Hussein Abuthuraya(MSFT))

11/16/2002 1:27:00 AM

0

Bill,

You have problem with the connectionstring. A sample code is:

cnOdbc = New OdbcConnection("Driver={Microsoft dBase Driver (*.dbf)};DBQ=D:\AccessDB\")

daOdbc = New OdbcDataAdapter("Select * from shippers", cnOdbc)
daOdbc.Fill(ds, "Text")

Not that the DBQ argument should point to the path only (no file.dbf specified). Also the name of the Driver was wrong (notice the "{}" and not "()" around the driver name also
notice the extra space before (*.dbf).

I hope this helps!


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.co....


Bob Grommes

11/17/2002 5:31:00 PM

0

In addition, you will need to prefix the argument to OdbcConnection with "@"
to keep the runtime from trying to parse \A as an escape sequence. Or else
double up on the backslashes to indicate they are not escape characters.

--Bob

"Hussein Abuthuraya(MSFT)" <HussAbOnline@microsoft.com> wrote in message
news:gKGB3aQjCHA.2464@cpmsftngxa06...
> Bill,
>
> You have problem with the connectionstring. A sample code is:
>
> cnOdbc = New OdbcConnection("Driver={Microsoft dBase Driver
(*.dbf)};DBQ=D:\AccessDB\")
>
> daOdbc = New OdbcDataAdapter("Select * from shippers", cnOdbc)
> daOdbc.Fill(ds, "Text")
>
> Not that the DBQ argument should point to the path only (no file.dbf
specified). Also the name of the Driver was wrong (notice the "{}" and not
"()" around the driver name also
> notice the extra space before (*.dbf).
>
> I hope this helps!
>
>
> Thanks,
> Hussein Abuthuraya
> Microsoft Developer Support
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>
> Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
> http://www.microsoft.co....
>
>


Bill

11/18/2002 4:26:00 AM

0

Bob, Hussein,

It's not clear to me where the "@" should go in my code. Could you
please clarify?

Also, even after having made the changes that Hussein suggested, i
still get a runtime error.

Here' s another thing that bothers me: when I use the syntax from
Hussein's example, I get syntax errors. I have to add a reference to
Microsoft.Data.Odbc to my solution, or the code won't compile. And
even with the namespace reference, I have to use the exact syntax in
the code I included...

It makes me thing that I doing some very basically wrong...

Thanks for you help...
Bill

On Sun, 17 Nov 2002 09:31:49 -0700, "Bob Grommes"
<bgrommes@fiestanet.com> wrote:

>In addition, you will need to prefix the argument to OdbcConnection with "@"
>to keep the runtime from trying to parse \A as an escape sequence. Or else
>double up on the backslashes to indicate they are not escape characters.
>
>--Bob
>
>"Hussein Abuthuraya(MSFT)" <HussAbOnline@microsoft.com> wrote in message
>news:gKGB3aQjCHA.2464@cpmsftngxa06...
>> Bill,
>>
>> You have problem with the connectionstring. A sample code is:
>>
>> cnOdbc = New OdbcConnection("Driver={Microsoft dBase Driver
>(*.dbf)};DBQ=D:\AccessDB\")
>>
>> daOdbc = New OdbcDataAdapter("Select * from shippers", cnOdbc)
>> daOdbc.Fill(ds, "Text")
>>
>> Not that the DBQ argument should point to the path only (no file.dbf
>specified). Also the name of the Driver was wrong (notice the "{}" and not
>"()" around the driver name also
>> notice the extra space before (*.dbf).
>>
>> I hope this helps!
>>
>>
>> Thanks,
>> Hussein Abuthuraya
>> Microsoft Developer Support
>>
>> This posting is provided "AS IS" with no warranties, and confers no
>rights.
>>
>> Are you secure? For information about the Microsoft Strategic Technology
>Protection Program and to order your FREE Security Tool Kit, please visit
>> http://www.microsoft.co....
>>
>>
>

Bob Grommes

11/18/2002 4:40:00 AM

0

Bill,

I was thinking in C#. On closer reading I see that you are using VB. So
ignore my comment and sorry for the confusion.

In C#, quoted strings are processed for escape sequences, e.g., \t = tab, \r
= return, etc. So any backslashes will be interpreted as an escape
character unless you double the backslash(es) or prefix the string with @,
that is:

"c:\\foo\\myfile.txt"
or
@"c:\foo\myfile.txt"

--Bob

"Bill" <elrefugio57@yahoo.com> wrote in message
news:b2ngtuo967s8r3kvne0ljh40nvij8uiui1@4ax.com...
> Bob, Hussein,
>
> It's not clear to me where the "@" should go in my code. Could you
> please clarify?
>
> Also, even after having made the changes that Hussein suggested, i
> still get a runtime error.
>
> Here' s another thing that bothers me: when I use the syntax from
> Hussein's example, I get syntax errors. I have to add a reference to
> Microsoft.Data.Odbc to my solution, or the code won't compile. And
> even with the namespace reference, I have to use the exact syntax in
> the code I included...
>
> It makes me thing that I doing some very basically wrong...
>
> Thanks for you help...
> Bill
>
> On Sun, 17 Nov 2002 09:31:49 -0700, "Bob Grommes"
> <bgrommes@fiestanet.com> wrote:
>
> >In addition, you will need to prefix the argument to OdbcConnection with
"@"
> >to keep the runtime from trying to parse \A as an escape sequence. Or
else
> >double up on the backslashes to indicate they are not escape characters.
> >
> >--Bob
> >
> >"Hussein Abuthuraya(MSFT)" <HussAbOnline@microsoft.com> wrote in message
> >news:gKGB3aQjCHA.2464@cpmsftngxa06...
> >> Bill,
> >>
> >> You have problem with the connectionstring. A sample code is:
> >>
> >> cnOdbc = New OdbcConnection("Driver={Microsoft dBase Driver
> >(*.dbf)};DBQ=D:\AccessDB\")
> >>
> >> daOdbc = New OdbcDataAdapter("Select * from shippers", cnOdbc)
> >> daOdbc.Fill(ds, "Text")
> >>
> >> Not that the DBQ argument should point to the path only (no file.dbf
> >specified). Also the name of the Driver was wrong (notice the "{}" and
not
> >"()" around the driver name also
> >> notice the extra space before (*.dbf).
> >>
> >> I hope this helps!
> >>
> >>
> >> Thanks,
> >> Hussein Abuthuraya
> >> Microsoft Developer Support
> >>
> >> This posting is provided "AS IS" with no warranties, and confers no
> >rights.
> >>
> >> Are you secure? For information about the Microsoft Strategic
Technology
> >Protection Program and to order your FREE Security Tool Kit, please visit
> >> http://www.microsoft.co....
> >>
> >>
> >
>


(Hussein Abuthuraya(MSFT))

11/19/2002 12:17:00 AM

0

Bill,

Adding a Reference to the project is not enough so that knows where to locate your objects. In addition to adding a reference, you need to Import the name space in the
Form's general decleration area or you need to qualify all the objects with full name space. The Import's syntax is:

Imports Microsoft.Data.Odbc

Public Class Form1
.....


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.co....


Bill

11/19/2002 2:40:00 AM

0

Hussein,
Thanks! That'll save me a lot of time...
Bill
On Mon, 18 Nov 2002 23:17:16 GMT, HussAbOnline@microsoft.com (Hussein
Abuthuraya(MSFT)) wrote:

>Bill,
>
>Adding a Reference to the project is not enough so that knows where to locate your objects. In addition to adding a reference, you need to Import the name space in the
>Form's general decleration area or you need to qualify all the objects with full name space. The Import's syntax is:
>
>Imports Microsoft.Data.Odbc
>
>Public Class Form1
>.....
>
>
>Thanks,
>Hussein Abuthuraya
>Microsoft Developer Support
>
>This posting is provided "AS IS" with no warranties, and confers no rights.
>
>Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
>http://www.microsoft.co....
>

Stan

11/25/2002 4:07:00 AM

0

Hello,
I follow all your discussion and i try to connect to a dbf file like the
following steps:

* i have a file "c:\toto\mabd.dbf"
* i create a new project c# in .NET
* i create a button1 on the form
* i create a datagrid1 on the form
* here is my "Form1.cs"

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Data.Odbc;

namespace odbcessai
{
public class Form1 : Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
...
// Dispose
...
// Windows Form Designer generated code
...
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
try
{
OdbcConnection essc = new OdbcConnection(@"Driver={Microsoft
dBase Driver (*.dbf)};DBQ=c:\toto\");
OdbcDataAdapter essda = new OdbcDataAdapter("Select * from
MABD", essc);
DataSet essds = new DataSet();
essda.Fill(essds);
dataGrid1.DataSource = essds;
}
catch(System.IO.FileNotFoundException rerere)
{
MessageBox.Show("File not found");
}
}
}

I think that there is a syntax problem with the argument in dataadapter
creation. I don't know ?!
In result, if i run the application, and click on button1, an error occur
"FileNotFoundException" before my message"file not found" and debug stop at
the line under "Application.Run(new Form1());"

Try to do this, please and answer me the right corrections.
I you have any quetions... i'll be here, It's Important.

TIA


(Hussein Abuthuraya(MSFT))

11/25/2002 10:35:00 PM

0

Your code works when I try it in C# Windows Form. If you are running it from WebForms then you are running into an issue where security is an issue. The folder that has the
DBF file and the DBF file itself should allow the IUSR or IWAM account to have permissions on the folder.

I hope this helsp!


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.co....