Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / June 2007

Tip: Looking for answers? Try searching our database.

ODBC and C# Express edition

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Colin Williams - 14 Jun 2007 21:41 GMT
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
Kevin Spencer - 15 Jun 2007 11:29 GMT
Hi Colin,

Here's a basic example (using a DataGridView) with comments:

// Declare the BindingSource variable
private System.Windows.Forms.BindingSource warehouseBindingSource;

// InitializeComponent method to add components to form
private void InitializeComponent()
{
//...
this.components = new System.ComponentModel.Container();
//...
// Create BindingSource and add to components
this.warehouseBindingSource = new
System.Windows.Forms.BindingSource(this.components);

// Initialize the component
((System.ComponentModel.ISupportInitialize)(this.warehouseBindingSource)).BeginInit();

// Assign BindingSource to DataGridView
this.warehouseGridView.BindingSource = this.warehouseBindingSource;

// Identify DataTable in DataSet to be bound to
this.warehouseBindingSource.DataMember = "Warehouse";

// Identify BindingSource (DataSet) to be bound to
this.warehouseBindingSource.DataSource = this.inventoryDataSet;

// End Initialization
((System.ComponentModel.ISupportInitialize)(this.warehouseBindingSource)).EndInit();
//...
}

// Form constructor method
public Form1()
{
//...
// Call InitializeComponent
InitializeComponent();
// ...
// Fill DataSet from TableAdapter
this.warehouseTableAdapter.Fill(this.inventoryDataSet.Warehouse);
//...
}

Signature

HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

> Hi
>
[quoted text clipped - 55 lines]
>
> Colin Williams

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.