C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-11-2007, 02:55 PM   #1
Registered User
 
Join Date: Dec 2007
Posts: 5
Creating a Data Adapter

Hey All;

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   Reply With Quote
Old 12-11-2007, 06:41 PM   #2
Super Moderator
 
Bubba's Avatar
 
Join Date: Aug 2001
Posts: 7,819
Please use code tags.
Bubba is offline   Reply With Quote
Old 12-11-2007, 07:59 PM   #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   Reply With Quote
Old 12-13-2007, 12:22 AM   #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();
		}
		}
		}
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);
Denis is offline   Reply With Quote
Old 12-13-2007, 01:05 PM   #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   Reply With Quote
Old 12-13-2007, 01:55 PM   #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   Reply With Quote
Old 12-13-2007, 04:16 PM   #7
Registered User
 
Join Date: Mar 2005
Location: Mountaintop, Pa
Posts: 1,059
It's missing:

Code:
using System.Data;
BobS0327 is offline   Reply With Quote
Old 12-13-2007, 07:17 PM   #8
Registered User
 
Join Date: Dec 2007
Posts: 5
oh jesus.... now i feel like an absolute idiot..... Thanks bob
Denis is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 08:40 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22