ive been told to put all my sql statement together but i jus keep getting lots of errors with local variables in my vc++ project.

sql.h

#ifndef __SQL_H__
#define __SQL_H__


#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;
using namespace System::Data::SQLite;
using namespace System::Data;
using namespace System::Windows::Forms;
using namespace System;


class sql
{
	public:
	
		void click(Label ^label1);
		
		
		void worknow(TextBox ^textBox1);
		//not working

};

#endif

my cpp file:

#include "stdafx.h"
#include "sql.h"
#include <string>


using namespace System;
using namespace System::Data::SQLite;
using namespace System::Data;
using namespace System::Windows::Forms;

void sql::click(Label ^label1) {

SQLiteConnection^ ObjConnection = gcnew SQLiteConnection("Data Source=database.db3;");
SQLiteCommand^ ObjCommand = gcnew SQLiteCommand("SELECT * FROM employee", ObjConnection);
ObjCommand->CommandType = CommandType::Text;
SQLiteDataAdapter^ ObjDataAdapter = gcnew SQLiteDataAdapter(ObjCommand);
DataSet^ dataSet = gcnew DataSet();
ObjDataAdapter->Fill(dataSet, "employee");
label1->DataBindings->Add("Text", dataSet->Tables["employee"],"firstname");
			}


void sql::worknow(TextBox ^textBox1) {

SQLiteConnection^ ObjConnection = gcnew SQLiteConnection("Data Source=database.db3;");
SQLiteCommand^ ObjCommand = gcnew SQLiteCommand("DELETE FROM employee WHERE id = ('"+worked+"')", ObjConnection);
ObjCommand->CommandType = CommandType::Text;
SQLiteDataAdapter^ ObjDataAdapter = gcnew SQLiteDataAdapter(ObjCommand);
DataSet^ dataSet = gcnew DataSet();
ObjDataAdapter->Fill(dataSet, "employee");

also have a windows form which am going to call the method:
button click.....

sql cmd
cmd2.worked(textBox1,);

my error output:
sql.cpp(28) : error C2065: 'worked' : undeclared identifier

'worked' does not appear at all in line 28, so I'm assuming you haven't pasted the code the same as it appears in your file?

You should get rid of lines 9 to 13 in sql.h. Do not import namespaces in a header file! You are polluting the name space and you run into the risk of name clashes. When someone includes your header file in their project, all of a sudden, they have imported five huge namespaces without knowing it... that is very bad.

Other than that, as David said, "worked" is undefined, because it is not declared anywhere that I can see in the code you posted. Usually, compilation error messages are accurate, if it says "undeclared", look for the declaration of it, if you can't find it, you have a problem. Using a variable that you haven't declared is usually either a sign of misunderstanding of the scope of the variables you declare, or just some vestige of successive coding trial-and-error that left trash variables around (either declared but not used or used but not declared)... or a sign that you have no idea what you are doing (hopefully you are not in the latter case).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.