Using ODBC with C# 2005 Express Edition

C

Colin Williams

Hi

I have some paradox db's i need to connect to. I have figured out that
i can do this using ODBC, however C# Express edition does not support
this connectivity easily and must be done programmatically. I have a
class to do this:

public static class Data
{
public const string SelectAllCommandText = "select * from
WindowInfo";

public static string ConnectionString;

public static DataSet GetWinInfoDataSet()
{
if (string.IsNullOrEmpty(ConnectionString))
throw new ArgumentNullException("ConnectionString");

DataSet result = new DataSet("WinInfo");

using (OdbcConnection connection = new
OdbcConnection(ConnectionString))
{
using (OdbcCommand command = new
OdbcCommand(SelectAllCommandText))
{
command.Connection = connection;
using (OdbcDataAdapter dataAdapter = new
OdbcDataAdapter(command))
{
dataAdapter.Fill(result);
connection.Close();
}
}
}
return result;
}
}

Which seems OK.
Need nelp on how to populate/bind a datagridview on my form. How can
tweak the code below to do this?

private void FormMain_Load(object sender, EventArgs e)
{

Data.ConnectionString = Settings.Default.ConnectionString;

dataSet1 = Data.GetWinInfoDataSet();
bindingSource1.DataSource =
dataSet1.Tables["WindowInfo"] ;
dataGridView1.DataSource = bindingSource1;

}


Many Thanks

Colin Williams
 
P

Peter Duniho

I have some paradox db's i need to connect to. I have figured out that
i can do this using ODBC, however C# Express edition does not support
this connectivity easily and must be done programmatically. [...]

You multi-posted this to at least two different newsgroups (this one and
m.p.dotnet.framework). Please learn to cross-post properly by including
all newsgroups in the Newsgroups: field of the same post.

Thank you.
 
C

Colin Williams

I have some paradox db's i need to connect to. I have figured out that
i can do this using ODBC, however C# Express edition does not support
this connectivity easily and must be done programmatically. [...]

You multi-posted this to at least two different newsgroups (this one and
m.p.dotnet.framework). Please learn to cross-post properly by including
all newsgroups in the Newsgroups: field of the same post.

Thank you.

Peter

Apologies for the incovenience this must have caused. I will look into
cross posting.
Regards
Colin Williams

Experience is something you dont have until just after you need it. ;)
 
N

Nicholas Paldino [.NET/C# MVP]

Colin,

It looks like it is doing it just fine. Is it not showing anything, are
you getting an exception? More information is needed.
 
C

Colin Williams

Thanks for the reply
No exceptions, but no records are being returned to the grid either.
Im stumped.

Regards

Colin Williams
 
N

Nicholas Paldino [.NET/C# MVP]

Colin,

Are you sure about that? In Windows Forms, when an exception occurs in
an event handler, it is swallowed by the control. You need to wrap the code
in the Load event in a try/catch block and step through it in order to see
if there is an exception.
 
C

Colin Williams

Nicholas

Tried your advice and no exceptions. I have now solved the problem by
adding the table name to the dataAdapter.fill() method.
i.e
dataAdapter.Fill(result,"table name");
Many thanks for you help.

Colin Williams
 
C

Colin Williams

Now i can see the data except for the blob fields. This i anticipated.
How do i go about retrieving these?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top