Using ODBC with C# 2005 Express Edition

  • Thread starter Thread starter Colin Williams
  • Start date Start date
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
 
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.
 
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. ;)
 
Colin,

It looks like it is doing it just fine. Is it not showing anything, are
you getting an exception? More information is needed.
 
Thanks for the reply
No exceptions, but no records are being returned to the grid either.
Im stumped.

Regards

Colin Williams
 
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.
 
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
 
Now i can see the data except for the blob fields. This i anticipated.
How do i go about retrieving these?
 
Back
Top