Code:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Database_Example
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class fclsMain : Form
{
OleDbConnection m_cnADONetConnection =new OleDbConnection();
DataTable m_dtContacts =new DataTable();
int m_rowPosition = 0;
public fclsMain()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void FclsMainLoad(object sender, EventArgs e)
{
m_cnADONetConnection.ConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Charlynne Guay\My Documents\Guild Items.xls";
OleDbDataAdapter m_daDataAdapter = new OleDbDataAdapter();
m_daDataAdapter = new OleDbDataAdapter("Select * From Contacts",m_cnADONetConnection);
OleDbCommandBuilder m_cbCommandBuilder = new OleDbCommandBuilder(m_daDataAdapter);
m_daDataAdapter.Fill(m_dtContacts);
}
void FclsMainFormClosed(object sender, FormClosedEventArgs e)
{
m_cnADONetConnection.Close();
}
}
}
Ok and this is what my course is telling me to do...... but I have no idea how to fix it. I'm getting an error on the color changed section
Creating and Populating DataTables
You're going to create a module-level DataTable in your project. First, create the DataTable variable by adding the following statement on the line below the statement you entered previously to declare a new module-level m_daDataAdapter object:
Code:
DataTable m_dtContacts = new DataTable();
You are going to use an integer variable to keep track of the user's current position within the DataTable. To do this, add the following statement immediately below the statement you just entered to declare the new DataTable object:
Code:
int m_rowPosition = 0;
Next, add the following statement to the Load event of the form, immediately following the statement that creates the CommandBuilder:
Code:
m_daDataAdapter.Fill(m_dtContacts);