ADO Problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
Need help with this:
I am trying to connect to an existing Access Database via ODBC.
My code is like this: It always generates a system error.
What am I doing wrong? Any help much appreciated.
-----------------------------------------------------------
'Code in VB.net
Dim conn As String = InputBox("Conn string?")
Dim sql As String = InputBox("Sql string?")
Dim dt As New DataTable

Dim co As New Odbc.OdbcConnection(conn)
co.Open()
Dim dataadapter As New _
System.Data.Odbc.OdbcDataAdapter(sql, co)
dataadapter.Fill(dt)
dataadapter.Dispose()

Me.DataGrid1.DataSource = d
 
Hi Rakesh,
Thanks for your reply.
------------------------------------------------------------------
The Exception occurs at Co.Open()and the message is:

An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in
system.data.dll

Additional information: System error
 
Re check your connection string.

- Rakesh Rajan

Mark said:
Hi Rakesh,
Thanks for your reply.
------------------------------------------------------------------
The Exception occurs at Co.Open()and the message is:

An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in
system.data.dll

Additional information: System error.
-------------------------------------------------------------------------- ---------------
Hope this helps.

Rakesh Rajan said:
Hi Mark,

What is the exception type?

- Rakesh Rajan

Mark said:
Hello,
Need help with this:
I am trying to connect to an existing Access Database via ODBC.
My code is like this: It always generates a system error.
What am I doing wrong? Any help much appreciated.
-----------------------------------------------------------
'Code in VB.net
Dim conn As String = InputBox("Conn string?")
Dim sql As String = InputBox("Sql string?")
Dim dt As New DataTable

Dim co As New Odbc.OdbcConnection(conn)
co.Open()
Dim dataadapter As New _
System.Data.Odbc.OdbcDataAdapter(sql, co)
dataadapter.Fill(dt)
dataadapter.Dispose()

Me.DataGrid1.DataSource = dt
--------------------------------------------------------------------------
 
Hi Miha & Rakesh,
Thanks for your replies.
This is my connection string:
Provider=MSDASQL.1;Persist Security Info=False;Data Source=SOURCE1

1. What is wrong ?
2. Code sample for the "correct way" will be appreciated.

Regards,
Mark

Miha Markic said:
Ah, I guess the connection string is not properly formated then.
 
Mark,

I suggest you the following.
Create empty project.
Add the ODBC (why not OleDb by the way?) connection to your dtb to Server
Explorer, drag&drop the connection on a form.
It will create an OdbcConnection for you - check the Windows Designer code
that was generated...

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Mark said:
Hi Miha & Rakesh,
Thanks for your replies.
This is my connection string:
Provider=MSDASQL.1;Persist Security Info=False;Data Source=SOURCE1

1. What is wrong ?
2. Code sample for the "correct way" will be appreciated.

Regards,
Mark

Miha Markic said:
Ah, I guess the connection string is not properly formated then.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Mark said:
Hi Rakesh,
Thanks for your reply.
------------------------------------------------------------------
The Exception occurs at Co.Open()and the message is:

An unhandled exception of type 'System.Data.Odbc.OdbcException'
occurred
in
system.data.dll

Additional information: System error.
-----------------------------------------------------------------------------------------
Hope this helps.

:

Hi Mark,

What is the exception type?

- Rakesh Rajan

Hello,
Need help with this:
I am trying to connect to an existing Access Database via ODBC.
My code is like this: It always generates a system error.
What am I doing wrong? Any help much appreciated.
-----------------------------------------------------------
'Code in VB.net
Dim conn As String = InputBox("Conn string?")
Dim sql As String = InputBox("Sql string?")
Dim dt As New DataTable

Dim co As New Odbc.OdbcConnection(conn)
co.Open()
Dim dataadapter As New _
System.Data.Odbc.OdbcDataAdapter(sql, co)
dataadapter.Fill(dt)
dataadapter.Dispose()

Me.DataGrid1.DataSource = dt
 
Thanks!
Will do.

Mark

Miha Markic said:
Mark,

I suggest you the following.
Create empty project.
Add the ODBC (why not OleDb by the way?) connection to your dtb to Server
Explorer, drag&drop the connection on a form.
It will create an OdbcConnection for you - check the Windows Designer code
that was generated...

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Mark said:
Hi Miha & Rakesh,
Thanks for your replies.
This is my connection string:
Provider=MSDASQL.1;Persist Security Info=False;Data Source=SOURCE1

1. What is wrong ?
2. Code sample for the "correct way" will be appreciated.

Regards,
Mark

Miha Markic said:
Ah, I guess the connection string is not properly formated then.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Hi Rakesh,
Thanks for your reply.
------------------------------------------------------------------
The Exception occurs at Co.Open()and the message is:

An unhandled exception of type 'System.Data.Odbc.OdbcException'
occurred
in
system.data.dll

Additional information: System error.
-----------------------------------------------------------------------------------------
Hope this helps.

:

Hi Mark,

What is the exception type?

- Rakesh Rajan

Hello,
Need help with this:
I am trying to connect to an existing Access Database via ODBC.
My code is like this: It always generates a system error.
What am I doing wrong? Any help much appreciated.
-----------------------------------------------------------
'Code in VB.net
Dim conn As String = InputBox("Conn string?")
Dim sql As String = InputBox("Sql string?")
Dim dt As New DataTable

Dim co As New Odbc.OdbcConnection(conn)
co.Open()
Dim dataadapter As New _
System.Data.Odbc.OdbcDataAdapter(sql, co)
dataadapter.Fill(dt)
dataadapter.Dispose()

Me.DataGrid1.DataSource = dt
 
Back
Top