![]() |
| | #1 |
| Registered User Join Date: Dec 2007
Posts: 5
| Creating a Data Adapter I'm new to C# and Have been working on finishing this online course I've been taking. I am wondering if you can help me figure out what is wrong with this code, and how to fix it. This is what I have in my coding: public partial class fclsMain : Form { OleDbConnection m_cnADONetConnection = new OleDbConnection(); m_daDataAdapter DataTable m_dtContacts = new DataTable(); int m_rowPosition = 0; public fclsMain() { This is what its telling me to place it as 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: DataTable m_dtContacts = new DataTable(); Please help! Last edited by Denis; 12-11-2007 at 06:50 PM. Reason: Code tags? This is exactly how my programming language is sitting exactly in the IDE. |
| Denis is offline | |
| | #2 |
| Super Moderator Join Date: Aug 2001
Posts: 7,819
| Please use code tags. |
| Bubba is offline | |
| | #3 |
| Registered User Join Date: Mar 2005 Location: Mountaintop, Pa
Posts: 1,059
| Code: public static void Main()
{
OleDbConnection m_cnADONetConnection = new OleDbConnection();
m_cnADONetConnection.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source= c:\\test.mdb";
m_cnADONetConnection.Open();
string sql="Select * from TestTable";
OleDbCommand com=new OleDbCommand(sql,m_cnADONetConnection );
OleDataAdapter m_daDataAdapter =new OleDbDataAdapter(com);
DataTable m_dtContacts =new DataTable();
m_daDataAdapter.Fill(m_dtContacts);
m_cnADONetConnection .Close();
// Additional processing such as displaying the records
}
Last edited by BobS0327; 12-11-2007 at 08:05 PM. |
| BobS0327 is offline | |
| | #4 |
| Registered User Join Date: Dec 2007
Posts: 5
| 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();
}
}
}
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(); Code: int m_rowPosition = 0; Code: m_daDataAdapter.Fill(m_dtContacts); |
| Denis is offline | |
| | #5 |
| Registered User Join Date: Mar 2005 Location: Mountaintop, Pa
Posts: 1,059
| Please post the desription of the error such as the error number which is usually a CS#### number and what the compiler is complaining about. |
| BobS0327 is offline | |
| | #6 |
| Registered User Join Date: Dec 2007
Posts: 5
| Ok won't let me edit my last post so here it is: The compiler and error message is saying The type or namespace name DataTable could not be found (are you missing a using directive or an assembly reference?) |
| Denis is offline | |
| | #7 |
| Registered User Join Date: Mar 2005 Location: Mountaintop, Pa
Posts: 1,059
| It's missing: Code: using System.Data; |
| BobS0327 is offline | |
| | #8 |
| Registered User Join Date: Dec 2007
Posts: 5
| oh jesus.... now i feel like an absolute idiot..... Thanks bob |
| Denis is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Lame null append cause buffer to crash | cmoo | C Programming | 8 | 12-29-2008 03:27 AM |
| Reading a file with Courier New characters | Noam | C Programming | 3 | 07-07-2006 09:29 AM |
| [question]Analyzing data in a two-dimensional array[with code] | burbose | C Programming | 4 | 06-14-2005 05:45 AM |
| C diamonds and perls :°) | Carlos | A Brief History of Cprogramming.com | 7 | 05-16-2003 10:19 PM |
| C Programming Question | TK | A Brief History of Cprogramming.com | 13 | 07-04-2002 07:11 PM |