two or more datareader

two or more datareader

Postby aspirany » Sat 14 Oct 2006 08:12

Dear CoreLab Team!

when i run two or more dataReader and after run dataset take an error message: There is already an open DataReader associated with this Connection which must be closed first.

but there is only on datareader in while everything is ok.


MySqlCommand^ command = gcnewMySqlCommand(sql, Connection);
MySqlDataReader^ dataReader = command->ExecuteReader();
cbRaktar->Items->Clear();

while (dataReader->Read()){
String^ raktID = dataReader["xyz"]->ToString();
String^ raktNev = dataReader["abc"]->ToString();

cbRaktar->Items->Add(raktID +" "+ raktNev);

}
aspirany
 
Posts: 12
Joined: Mon 04 Sep 2006 16:51

Postby aspirany » Sat 14 Oct 2006 09:18

ps: i close datreader and connection

}
datreader->Close();
Connection->Close();
aspirany
 
Posts: 12
Joined: Mon 04 Sep 2006 16:51

Postby Alexey » Mon 16 Oct 2006 07:07

when i run two or more dataReader

Where is the second one?
Please provide us with full code snippet and specify the string where error occurs.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby aspirany » Mon 16 Oct 2006 14:38

the first post i mean there's only one datareader, sorry.

example:

void...._dropdown(....){

MySqlCommand^ command = gcnewMySqlCommand(sql, Connection);
MySqlDataReader^ dataReader = command->ExecuteReader();
cbRaktar->Items->Clear();

while (dataReader->Read()){
String^ raktID = dataReader["xyz"]->ToString();

cbRaktar->Items->Add(raktID);

}
datreader->Close();
Connection->Close();
}

void....._click(...){

clearing dataset

sql(select * from xyz where raktID='raktID')

fill dataset
}

everything is ok, working dropdown and click.

after i modify the code and run dropdown and run click:

There is already an open DataReader associated with this Connection which must be closed first.

void...._dropdown(....){

MySqlCommand^ command = gcnewMySqlCommand(sql, Connection);
MySqlDataReader^ dataReader = command->ExecuteReader();
cbRaktar->Items->Clear();

while (dataReader->Read()){
String^ raktID = dataReader["xyz"]->ToString();
String^ raktNev = dataReader["xyz"]->ToString();

cbRaktar->Items->Add(raktID +" "+ raktNev);

}
datreader->Close();
Connection->Close();
}

void....._click(...){

clearing dataset

sql(select * from xyz where raktID='raktID')

fill dataset
}
aspirany
 
Posts: 12
Joined: Mon 04 Sep 2006 16:51

Postby Alexey » Tue 17 Oct 2006 07:09

Too much syntax errors in your code. Also this is unclear what "clearing dataset" and "fill dataset" mean. Please send us working and compilable test project to reproduce the problem; it is desirable to use 'test' schema objects, otherwise include definition of your own database objects. Use e-mail address provided in the Readme file. Do not use third party components.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby aspirany » Tue 17 Oct 2006 07:27

#pragma once
#include "Kosarba.h"

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


namespace bizonylat {

///
/// Summary for Bizonylat
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
///

public ref class Bizonylat : public System::Windows::Forms::Form
{
System::String^ bizID;
public:
Bizonylat(String^ bizid)
{
//
// Required for Windows Form Designer support
//
bizID = bizid;
InitializeComponent();

}

Bizonylat(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}

protected:
///
/// Clean up any resources being used.
///

~Bizonylat()
{
if (components)
{
delete components;
}
}

private: System::Windows::Forms::TabControl^ tabControl1;
private: System::Windows::Forms::TabPage^ tbpBongeszo;
private: System::Windows::Forms::TabPage^ tbpKosar;
private: System::Windows::Forms::TabPage^ tbpBizonylat;
private: System::Windows::Forms::DataGridView^ BongeszoGridView;
private: System::Data::DataSet^ dataSet;
private: MySql::Data::MySqlClient::MySqlConnection^ Connection;
private: MySql::Data::MySqlClient::MySqlCommand^ BongeszoCommand;
private: MySql::Data::MySqlClient::MySqlCommandBuilder^ BongeszoCommandBuilder;
private: MySql::Data::MySqlClient::MySqlDataAdapter^ BongeszoDataAdapter;
private: MySql::Data::MySqlClient::MySqlCommand^ KosarCommand;
private: MySql::Data::MySqlClient::MySqlCommandBuilder^ KosarCommandBuilder;
private: MySql::Data::MySqlClient::MySqlDataAdapter^ KosarDataAdapter;
private: System::Windows::Forms::Button^ btBongeszoBezar;
private: System::Windows::Forms::DataGridView^ KosarGridView;
private: System::Windows::Forms::Button^ btKosarBezar;
private: System::Windows::Forms::Button^ btLeker;
private: System::Windows::Forms::ComboBox^ cbRaktar;
private: System::Windows::Forms::Label^ lbRaktar;
private: System::Windows::Forms::TextBox^ tbCikk;
private: System::Windows::Forms::ComboBox^ cbStatusz;
private: System::Windows::Forms::TextBox^ tbMeret;
private: System::Windows::Forms::ComboBox^ cbCsoportnev;
private: System::Windows::Forms::TextBox^ tbCikknev;
private: System::Windows::Forms::TextBox^ tbCsaladnev;
private: System::Windows::Forms::TextBox^ tbSzCikk;
private: System::Windows::Forms::Label^ lbCikk;
private: System::Windows::Forms::CheckBox^ chbKeszletes;
private: System::Windows::Forms::Label^ lbCsoportnev;
private: System::Windows::Forms::Label^ lbSztetel;
private: System::Windows::Forms::TextBox^ tbSztetel;
private: System::Windows::Forms::Label^ lbSzcikk;
private: System::Windows::Forms::Label^ lbCikknev;
private: System::Windows::Forms::Label^ lbCsaladnev;
private: System::Windows::Forms::Label^ lbKeszletes;
private: System::Windows::Forms::Label^ lbStatusz;
private: System::Windows::Forms::Label^ lbMeret;
static int from;
static int limit;
static int meddig;
static int eredm;
static int length = 0;
static int maxlength = 1;


protected:

private:
///
/// Required designer variable.
///

System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

void InitializeComponent(void)
{
this->Connection = (gcnew MySql::Data::MySqlClient::MySqlConnection());
this->BongeszoCommand = (gcnew MySql::Data::MySqlClient::MySqlCommand());
this->BongeszoCommandBuilder = (gcnew MySql::Data::MySqlClient::MySqlCommandBuilder());
this->BongeszoDataAdapter = (gcnew MySql::Data::MySqlClient::MySqlDataAdapter());
this->KosarCommand = (gcnew MySql::Data::MySqlClient::MySqlCommand());
this->KosarCommandBuilder = (gcnew MySql::Data::MySqlClient::MySqlCommandBuilder());
this->KosarDataAdapter = (gcnew MySql::Data::MySqlClient::MySqlDataAdapter());
this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
this->tbpBongeszo = (gcnew System::Windows::Forms::TabPage());
this->lbKeszletes = (gcnew System::Windows::Forms::Label());
this->lbStatusz = (gcnew System::Windows::Forms::Label());
this->lbMeret = (gcnew System::Windows::Forms::Label());
this->lbCikknev = (gcnew System::Windows::Forms::Label());
this->lbCsaladnev = (gcnew System::Windows::Forms::Label());
this->lbCsoportnev = (gcnew System::Windows::Forms::Label());
this->lbSztetel = (gcnew System::Windows::Forms::Label());
this->tbSztetel = (gcnew System::Windows::Forms::TextBox());
this->lbSzcikk = (gcnew System::Windows::Forms::Label());
this->lbCikk = (gcnew System::Windows::Forms::Label());
this->chbKeszletes = (gcnew System::Windows::Forms::CheckBox());
this->cbStatusz = (gcnew System::Windows::Forms::ComboBox());
this->tbMeret = (gcnew System::Windows::Forms::TextBox());
this->cbCsoportnev = (gcnew System::Windows::Forms::ComboBox());
this->tbCikknev = (gcnew System::Windows::Forms::TextBox());
this->tbCsaladnev = (gcnew System::Windows::Forms::TextBox());
this->tbSzCikk = (gcnew System::Windows::Forms::TextBox());
this->tbCikk = (gcnew System::Windows::Forms::TextBox());
this->lbRaktar = (gcnew System::Windows::Forms::Label());
this->cbRaktar = (gcnew System::Windows::Forms::ComboBox());
this->btLeker = (gcnew System::Windows::Forms::Button());
this->btBongeszoBezar = (gcnew System::Windows::Forms::Button());
this->BongeszoGridView = (gcnew System::Windows::Forms::DataGridView());
this->tbpKosar = (gcnew System::Windows::Forms::TabPage());
this->btKosarBezar = (gcnew System::Windows::Forms::Button());
this->KosarGridView = (gcnew System::Windows::Forms::DataGridView());
this->tbpBizonylat = (gcnew System::Windows::Forms::TabPage());
this->dataSet = (gcnew System::Data::DataSet());
this->tabControl1->SuspendLayout();
this->tbpBongeszo->SuspendLayout();
(cli::safe_cast(this->BongeszoGridView))->BeginInit();
this->tbpKosar->SuspendLayout();
(cli::safe_cast(this->KosarGridView))->BeginInit();
(cli::safe_cast(this->dataSet))->BeginInit();
this->SuspendLayout();
//
// Connection
//
this->Connection->ConnectionString = L"User Id=root;Password=aspirany;Host=localhost;Database=karavan;";
//
// BongeszoCommand
//
this->BongeszoCommand->Connection = this->Connection;
//
// BongeszoCommandBuilder
//
this->BongeszoCommandBuilder->DataAdapter = this->BongeszoDataAdapter;
//
// BongeszoDataAdapter
//
this->BongeszoDataAdapter->MissingSchemaAction = System::Data::MissingSchemaAction::AddWithKey;
this->BongeszoDataAdapter->SelectCommand = this->BongeszoCommand;
//
// KosarCommand
//
this->KosarCommand->CommandText = L"";
this->KosarCommand->Connection = this->Connection;
//
// KosarCommandBuilder
//
this->KosarCommandBuilder->DataAdapter = this->KosarDataAdapter;
//
// KosarDataAdapter
//
this->KosarDataAdapter->MissingSchemaAction = System::Data::MissingSchemaAction::AddWithKey;
this->KosarDataAdapter->SelectCommand = this->KosarCommand;
//
// dataSet
//
this->dataSet->DataSetName = L"NewDataSet";
//
// tabControl1
//
this->tabControl1->Controls->Add(this->tbpBongeszo);
this->tabControl1->Controls->Add(this->tbpKosar);
this->tabControl1->Controls->Add(this->tbpBizonylat);
this->tabControl1->Location = System::Drawing::Point(13, 13);
this->tabControl1->Name = L"tabControl1";
this->tabControl1->SelectedIndex = 0;
this->tabControl1->Size = System::Drawing::Size(991, 613);
this->tabControl1->TabIndex = 0;
//
// tbpBongeszo
//
this->tbpBongeszo->Controls->Add(this->lbKeszletes);
this->tbpBongeszo->Controls->Add(this->lbStatusz);
this->tbpBongeszo->Controls->Add(this->lbMeret);
this->tbpBongeszo->Controls->Add(this->lbCikknev);
this->tbpBongeszo->Controls->Add(this->lbCsaladnev);
this->tbpBongeszo->Controls->Add(this->lbCsoportnev);
this->tbpBongeszo->Controls->Add(this->lbSztetel);
this->tbpBongeszo->Controls->Add(this->tbSztetel);
this->tbpBongeszo->Controls->Add(this->lbSzcikk);
this->tbpBongeszo->Controls->Add(this->lbCikk);
this->tbpBongeszo->Controls->Add(this->chbKeszletes);
this->tbpBongeszo->Controls->Add(this->cbStatusz);
this->tbpBongeszo->Controls->Add(this->tbMeret);
this->tbpBongeszo->Controls->Add(this->cbCsoportnev);
this->tbpBongeszo->Controls->Add(this->tbCikknev);
this->tbpBongeszo->Controls->Add(this->tbCsaladnev);
this->tbpBongeszo->Controls->Add(this->tbSzCikk);
this->tbpBongeszo->Controls->Add(this->tbCikk);
this->tbpBongeszo->Controls->Add(this->lbRaktar);
this->tbpBongeszo->Controls->Add(this->cbRaktar);
this->tbpBongeszo->Controls->Add(this->btLeker);
this->tbpBongeszo->Controls->Add(this->btBongeszoBezar);
this->tbpBongeszo->Controls->Add(this->BongeszoGridView);
this->tbpBongeszo->Location = System::Drawing::Point(4, 22);
this->tbpBongeszo->Name = L"tbpBongeszo";
this->tbpBongeszo->Padding = System::Windows::Forms::Padding(3);
this->tbpBongeszo->Size = System::Drawing::Size(983, 587);
this->tbpBongeszo->TabIndex = 0;
this->tbpBongeszo->Text = L"Bngsz";
this->tbpBongeszo->UseVisualStyleBackColor = true;
//
// lbKeszletes
//
this->lbKeszletes->AutoSize = true;
this->lbKeszletes->Location = System::Drawing::Point(886, 8);
this->lbKeszletes->Name = L"lbKeszletes";
this->lbKeszletes->Size = System::Drawing::Size(52, 13);
this->lbKeszletes->TabIndex = 0;
this->lbKeszletes->Text = L"Kszletes";
//
// lbStatusz
//
this->lbStatusz->AutoSize = true;
this->lbStatusz->Location = System::Drawing::Point(814, 8);
this->lbStatusz->Name = L"lbStatusz";
this->lbStatusz->Size = System::Drawing::Size(42, 13);
this->lbStatusz->TabIndex = 0;
this->lbStatusz->Text = L"Sttusz";
//
// lbMeret
//
this->lbMeret->AutoSize = true;
this->lbMeret->Location = System::Drawing::Point(737, 8);
this->lbMeret->Name = L"lbMeret";
this->lbMeret->Size = System::Drawing::Size(34, 13);
this->lbMeret->TabIndex = 0;
this->lbMeret->Text = L"Mret";
//
// lbCikknev
//
this->lbCikknev->AutoSize = true;
this->lbCikknev->Location = System::Drawing::Point(629, 8);
this->lbCikknev->Name = L"lbCikknev";
this->lbCikknev->Size = System::Drawing::Size(55, 13);
this->lbCikknev->TabIndex = 0;
this->lbCikknev->Text = L"Cikk neve";
//
// lbCsaladnev
//
this->lbCsaladnev->AutoSize = true;
this->lbCsaladnev->Location = System::Drawing::Point(512, 8);
this->lbCsaladnev->Name = L"lbCsaladnev";
this->lbCsaladnev->Size = System::Drawing::Size(57, 13);
this->lbCsaladnev->TabIndex = 0;
this->lbCsaladnev->Text = L"Csaldnv";
//
// lbCsoportnev
//
this->lbCsoportnev->AutoSize = true;
this->lbCsoportnev->Location = System::Drawing::Point(411, 8);
this->lbCsoportnev->Name = L"lbCsoportnev";
this->lbCsoportnev->Size = System::Drawing::Size(61, 13);
this->lbCsoportnev->TabIndex = 0;
this->lbCsoportnev->Text = L"Csoportnv";
//
// lbSztetel
//
this->lbSztetel->AutoSize = true;
this->lbSztetel->Location = System::Drawing::Point(326, 8);
this->lbSztetel->Name = L"lbSztetel";
this->lbSztetel->Size = System::Drawing::Size(42, 13);
this->lbSztetel->TabIndex = 0;
this->lbSztetel->Text = L"Sz.ttel";
//
// tbSztetel
//
this->tbSztetel->Location = System::Drawing::Point(297, 27);
this->tbSztetel->Name = L"tbSztetel";
this->tbSztetel->Size = System::Drawing::Size(100, 20);
this->tbSztetel->TabIndex = 4;
//
// lbSzcikk
//
this->lbSzcikk->AutoSize = true;
this->lbSzcikk->Location = System::Drawing::Point(216, 8);
this->lbSzcikk->Name = L"lbSzcikk";
this->lbSzcikk->Size = System::Drawing::Size(42, 13);
this->lbSzcikk->TabIndex = 0;
this->lbSzcikk->Text = L"Sz.cikk";
//
// lbCikk
//
this->lbCikk->AutoSize = true;
this->lbCikk->Location = System::Drawing::Point(112, 8);
this->lbCikk->Name = L"lbCikk";
this->lbCikk->Size = System::Drawing::Size(28, 13);
this->lbCikk->TabIndex = 0;
this->lbCikk->Text = L"Cikk";
//
// chbKeszletes
//
this->chbKeszletes->AutoSize = true;
this->chbKeszletes->Location = System::Drawing::Point(899, 29);
this->chbKeszletes->Name = L"chbKeszletes";
this->chbKeszletes->Size = System::Drawing::Size(15, 14);
this->chbKeszletes->TabIndex = 9;
this->chbKeszletes->UseVisualStyleBackColor = true;
//
// cbStatusz
//
this->cbStatusz->FormattingEnabled = true;
this->cbStatusz->Location = System::Drawing::Point(801, 27);
this->cbStatusz->Name = L"cbStatusz";
this->cbStatusz->Size = System::Drawing::Size(77, 21);
this->cbStatusz->TabIndex = 8;
this->cbStatusz->DropDown += gcnew System::EventHandler(this, &Bizonylat::cbStatusz_DropDown);
//
// tbMeret
//
this->tbMeret->Location = System::Drawing::Point(727, 27);
this->tbMeret->Name = L"tbMeret";
this->tbMeret->Size = System::Drawing::Size(57, 20);
this->tbMeret->TabIndex = 8;
//
// cbCsoportnev
//
this->cbCsoportnev->FormattingEnabled = true;
this->cbCsoportnev->Location = System::Drawing::Point(408, 27);
this->cbCsoportnev->Name = L"cbCsoportnev";
this->cbCsoportnev->Size = System::Drawing::Size(69, 21);
this->cbCsoportnev->TabIndex = 5;
this->cbCsoportnev->DropDown += gcnew System::EventHandler(this, &Bizonylat::cbCsoprtnev_DropDown);
//
// tbCikknev
//
this->tbCikknev->Location = System::Drawing::Point(611, 27);
this->tbCikknev->Name = L"tbCikknev";
this->tbCikknev->Size = System::Drawing::Size(100, 20);
this->tbCikknev->TabIndex = 7;
//
// tbCsaladnev
//
this->tbCsaladnev->Location = System::Drawing::Point(494, 27);
this->tbCsaladnev->Name = L"tbCsaladnev";
this->tbCsaladnev->Size = System::Drawing::Size(100, 20);
this->tbCsaladnev->TabIndex = 6;
//
// tbSzCikk
//
this->tbSzCikk->Location = System::Drawing::Point(188, 27);
this->tbSzCikk->Name = L"tbSzCikk";
this->tbSzCikk->Size = System::Drawing::Size(100, 20);
this->tbSzCikk->TabIndex = 3;
//
// tbCikk
//
this->tbCikk->Location = System::Drawing::Point(77, 27);
this->tbCikk->Name = L"tbCikk";
this->tbCikk->Size = System::Drawing::Size(100, 20);
this->tbCikk->TabIndex = 2;
this->tbCikk->Text = L"ALF";
//
// lbRaktar
//
this->lbRaktar->AutoSize = true;
this->lbRaktar->Location = System::Drawing::Point(19, 8);
this->lbRaktar->Name = L"lbRaktar";
this->lbRaktar->Size = System::Drawing::Size(39, 13);
this->lbRaktar->TabIndex = 0;
this->lbRaktar->Text = L"Raktr";
//
// cbRaktar
//
this->cbRaktar->DropDownWidth = maxlength;
this->cbRaktar->FormattingEnabled = true;
this->cbRaktar->Location = System::Drawing::Point(12, 27);
this->cbRaktar->Name = L"cbRaktar";
this->cbRaktar->Size = System::Drawing::Size(55, 21);
this->cbRaktar->TabIndex = 1;
this->cbRaktar->Text = L"1";
this->cbRaktar->DropDown += gcnew System::EventHandler(this, &Bizonylat::cbRaktar_DropDown);
//
// btLeker
//
this->btLeker->Location = System::Drawing::Point(926, 27);
this->btLeker->Name = L"btLeker";
this->btLeker->Size = System::Drawing::Size(35, 23);
this->btLeker->TabIndex = 10;
this->btLeker->Text = L"SZ";
this->btLeker->UseVisualStyleBackColor = true;
this->btLeker->Click += gcnew System::EventHandler(this, &Bizonylat::btLeker_Click);
//
// btBongeszoBezar
//
this->btBongeszoBezar->Location = System::Drawing::Point(292, 558);
this->btBongeszoBezar->Name = L"btBongeszoBezar";
this->btBongeszoBezar->Size = System::Drawing::Size(75, 23);
this->btBongeszoBezar->TabIndex = 1;
this->btBongeszoBezar->Text = L"Bezr";
this->btBongeszoBezar->UseVisualStyleBackColor = true;
this->btBongeszoBezar->Click += gcnew System::EventHandler(this, &Bizonylat::btKosarBezar_Click);
//
// BongeszoGridView
//
this->BongeszoGridView->AllowUserToAddRows = false;
this->BongeszoGridView->AllowUserToDeleteRows = false;
this->BongeszoGridView->AllowUserToOrderColumns = true;
this->BongeszoGridView->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->BongeszoGridView->Location = System::Drawing::Point(7, 57);
this->BongeszoGridView->Name = L"BongeszoGridView";
this->BongeszoGridView->ReadOnly = true;
this->BongeszoGridView->RowHeadersVisible = false;
this->BongeszoGridView->SelectionMode = System::Windows::Forms::DataGridViewSelectionMode::FullRowSelect;
this->BongeszoGridView->Size = System::Drawing::Size(970, 490);
this->BongeszoGridView->TabIndex = 0;
this->BongeszoGridView->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Bizonylat::BongeszoGridView_KeyDown);
this->BongeszoGridView->CellDoubleClick += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &Bizonylat::BongeszoGridView_CellDoubleClick);
//
// tbpKosar
//
this->tbpKosar->Controls->Add(this->btKosarBezar);
this->tbpKosar->Controls->Add(this->KosarGridView);
this->tbpKosar->Location = System::Drawing::Point(4, 22);
this->tbpKosar->Name = L"tbpKosar";
this->tbpKosar->Padding = System::Windows::Forms::Padding(3);
this->tbpKosar->Size = System::Drawing::Size(983, 587);
this->tbpKosar->TabIndex = 1;
this->tbpKosar->Text = L"Kosr";
this->tbpKosar->UseVisualStyleBackColor = true;
//
// KosarGridView
//
this->KosarGridView->AllowUserToAddRows = false;
this->KosarGridView->AllowUserToDeleteRows = false;
this->KosarGridView->AllowUserToOrderColumns = true;
this->KosarGridView->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->KosarGridView->Location = System::Drawing::Point(7, 41);
this->KosarGridView->Name = L"KosarGridView";
this->KosarGridView->ReadOnly = true;
this->KosarGridView->RowHeadersVisible = false;
this->KosarGridView->SelectionMode = System::Windows::Forms::DataGridViewSelectionMode::FullRowSelect;
this->KosarGridView->Size = System::Drawing::Size(970, 506);
this->KosarGridView->TabIndex = 0;
//
// btKosarBezar
//
this->btKosarBezar->Location = System::Drawing::Point(292, 558);
this->btKosarBezar->Name = L"btKosarBezar";
this->btKosarBezar->Size = System::Drawing::Size(75, 23);
this->btKosarBezar->TabIndex = 1;
this->btKosarBezar->Text = L"Bezar";
this->btKosarBezar->UseVisualStyleBackColor = true;
//
// tbpBizonylat
//
this->tbpBizonylat->Location = System::Drawing::Point(4, 22);
this->tbpBizonylat->Name = L"tbpBizonylat";
this->tbpBizonylat->Size = System::Drawing::Size(983, 587);
this->tbpBizonylat->TabIndex = 2;
this->tbpBizonylat->Text = L"Bizonylat";
this->tbpBizonylat->UseVisualStyleBackColor = true;
//
// Bizonylat
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(1016, 638);
this->Controls->Add(this->tabControl1);
this->Name = L"Bizonylat";
this->Text = L"Bizonylat";
this->Load += gcnew System::EventHandler(this, &Bizonylat::Bizonylat_Load);
this->WindowState = System::Windows::Forms::FormWindowState::Maximized;
this->tbpBongeszo->ResumeLayout(false);
this->tbpBongeszo->PerformLayout();
this->tbpKosar->ResumeLayout(false);
(cli::safe_cast(this->KosarGridView))->EndInit();
(cli::safe_cast(this->dataSet))->EndInit();
this->ResumeLayout(false);

}

private: System::Void Bizonylat_Load(System::Object^ sender, System::EventArgs^ e)
{
from = 0;
try{
Cursor->Current = Cursors::WaitCursor;
dataSet = gcnew System::Data::DataSet();
BongeszoGridView->DataSource = dataSet;
BongeszoGridView->DataMember = String::Empty;
dataSet->EnforceConstraints = false;
BongeszoCommand->CommandText = L"SELECT \n"+
L"COALESCE(keszlet.raktar,'1') AS Rakt,\n"+
L"cikk.cikk AS Cikk,\n"+
L"cikktonus.cikktonus AS Tnus,\n"+
L"cikk.gyarikod AS 'Sz.Cikk',\n"+
L"cikk.gyaritetel AS 'Sz.ttel',\n"+
L"cikkcsoport.cikkcsoportnev AS Csoprtnv,\n"+
L"cikk.cikkcsalad AS Csaldnv,\n"+
L"cikk.cikknev AS Cikkneve,\n"+
L"cikk.tulajdonsag AS Mret,\n"+
L"keszlet.mennyiseg AS Kszlet, \n"+
L"ROUND(arakt.kisker_ar*1.2) AS 'Egys.r' \n"+
L"FROM \n"+
L"keszlet \n"+
L"LEFT OUTER JOIN cikktonus ON (keszlet.cikktonus = cikktonus.cikktonus) \n"+
L"LEFT OUTER JOIN cikk ON (cikk.cikk = cikktonus.cikk) \n"+
L"AND (keszlet.cikk = cikk.cikk) \n"+
L"LEFT OUTER JOIN cikkcsoport ON (cikk.cikkcsoport = cikkcsoport.cikkcsoport) \n"+
L"LEFT OUTER JOIN `arakt` ON (cikk.cikk = `arakt`.cikk) \n"+
L"WHERE \n"+
L"(keszlet.raktar = '1') AND \n"+
L"(cikk.cikk LIKE 'ALF%') LIMIT 0,100";
BongeszoDataAdapter->Fill(dataSet, "Table");
BongeszoGridView->DataMember = "Table";
Cursor->Current = Cursors::Default;
}
catch (MySql::Data::MySqlClient::MySqlException^ exception)
{
MessageBox::Show(exception->Message,"Nincs kapcsolat az adatbzisal!");
}

String^ sql = L"SELECT COUNT(*) \n"
L"FROM \n"+
L"keszlet \n"+
L"LEFT OUTER JOIN cikktonus ON (keszlet.cikktonus = cikktonus.cikktonus) \n"+
L"LEFT OUTER JOIN cikk ON (cikk.cikk = cikktonus.cikk) \n"+
L"AND (keszlet.cikk = cikk.cikk) \n"+
L"LEFT OUTER JOIN cikkcsoport ON (cikk.cikkcsoport = cikkcsoport.cikkcsoport) \n"+
L"LEFT OUTER JOIN `arakt` ON (cikk.cikk = `arakt`.cikk) \n"+
L"WHERE \n"+
L"(keszlet.raktar = '1') AND \n"+
L"(cikk.cikk LIKE 'ALF%')";

MySql::Data::MySqlClient::MySqlCommand^ command = gcnew MySql::Data::MySqlClient::MySqlCommand(sql, Connection);
MySql::Data::MySqlClient::MySqlDataReader^ dataReader;

if (Connection->State == ConnectionState::Closed)
{
Connection->Open();
dataReader = command->ExecuteReader();
while (dataReader->Read()){
eredm = dataReader->GetInt32(0);
}
}
dataReader->Close();
Connection->Close();
}

private: System::Void btBongeszoBezar_Click(System::Object^ sender, System::EventArgs^ e)
{
Bizonylat::Close();
}

private: System::Void btKosarBezar_Click(System::Object^ sender, System::EventArgs^ e)
{
Bizonylat::Close();
}

private: System::Void BongeszoGridView_CellDoubleClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e)
{
DataGridViewRow^ selectRow = BongeszoGridView->CurrentRow;
String^ raktarID = selectRow->Cells[0]->Value->ToString();
String^ cikkID = selectRow->Cells[1]->Value->ToString();
String^ cikkTonus = selectRow->Cells[2]->Value->ToString();
kosarba::Kosarba^ KosarbaForm = gcnew kosarba::Kosarba(raktarID,cikkID,cikkTonus);
KosarbaForm->Show();
}

private: System::Void btLeker_Click(System::Object^ sender, System::EventArgs^ e) {

try{
Cursor->Current = Cursors::WaitCursor;
this->dataSet = gcnew System::Data::DataSet();
BongeszoGridView->DataSource = this->dataSet;
BongeszoGridView->DataMember = String::Empty;
count();
szures();
this->BongeszoCommand->Connection = this->Connection;
this->dataSet->EnforceConstraints = false;
BongeszoDataAdapter->Fill(dataSet, "Table");
BongeszoGridView->DataMember = "Table";
Cursor->Current = Cursors::Default;
}
catch (MySql::Data::MySqlClient::MySqlException^ exception)
{
MessageBox::Show(exception->Message,"Hiba! Lpjen kapcsolatba a rendszergazdval!");
}
}

private: System::Void tabControl1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e){

String^ index=tabControl1->SelectedTab->Text;
if(index=="Kosr")
//String^ bizID = BongeszoGridView->CurrentCell->Value->ToString();
this->dataSet = gcnew System::Data::DataSet();
KosarGridView->DataSource = this->dataSet;
KosarGridView->DataMember = String::Empty;
this->KosarCommand->CommandText = L"SELECT "+
"cart.termekId,"+
"cart.bizszam,"+
"cart.ar,"+
"cart.qty,"+
"cart.raktId,"+
"termek.termeknev,"+
"termek.suly,"+
"arak.beszar,"+
"COALESCE(raktar.keszlet, 0) AS keszlet,"+
"SUM(COALESCE(keszletfoglalas.qty,0)) AS foglalas,"+
"raktar.keszlet - SUM(COALESCE(keszletfoglalas.qty,0)) AS kiadhato "+
"FROM termek "+
"LEFT JOIN cart ON (termek.termekId = cart.termekId) "+
"LEFT JOIN raktar ON (cart.termekId = raktar.termekId) AND (cart.raktId = raktar.raktId) "+
"LEFT JOIN keszletfoglalas ON (cart.termekId = keszletfoglalas.termekId) AND (cart.raktId = keszletfoglalas.raktId),arak,arkod "+
"WHERE (cart.bizszam = \"+bizID+"\) AND "+
"(termek.arkod = arak.arkod) AND "+
"(arak.arkodId = arkod.arkodId) AND "+
"(arkod.arkodId = '1') "+
"GROUP BY cart.termekId,cart.bizszam,cart.ar,"+
"cart.qty,cart.raktId,termek.termeknev,termek.suly,arak.beszar";
this->KosarCommand->Connection = this->Connection;
KosarDataAdapter->Fill(dataSet, "Table");
KosarGridView->DataMember = "Table";

}

private: System::Void cbRaktar_DropDown(System::Object^ sender, System::EventArgs^ e)
{

if (Connection->State == ConnectionState::Closed)
{
Connection->Open();
String^ sql = "SELECT \n"+
"raktar.raktar,\n"+
"partner.partnernev \n"+
"FROM \n"+
"partner \n"
"RIGHT OUTER JOIN raktar ON (partner.partnerId = raktar.raktar)";

MySql::Data::MySqlClient::MySqlCommand^ command = gcnew MySql::Data::MySqlClient::MySqlCommand(sql, Connection);
MySql::Data::MySqlClient::MySqlDataReader^ dataReader = command->ExecuteReader();
cbRaktar->Items->Clear();
int length = 0;

while (dataReader->Read()){
//cbRaktar->Items->Add(dataReader->GetString(0)+" "+dataReader->GetString(1));
String^ raktID = dataReader["raktar"]->ToString();
String^ raktNev = dataReader["partnernev"]->ToString();

length = Convert::ToInt32(raktNev->Length.ToString());
if(maxlength maxlength=length;

cbRaktar->Items->Add(raktID +" "+ raktNev);

}

dataReader->Close();
Connection->Close();
}
}

private: System::Void cbCsoprtnev_DropDown(System::Object^ sender, System::EventArgs^ e)
{
if (Connection->State == ConnectionState::Closed)
{
Connection->Open();
String^ sql = "SELECT cikkcsoportnev From cikkcsoport ORDER BY cikkcsoportnev";

MySql::Data::MySqlClient::MySqlCommand^ command = gcnew MySql::Data::MySqlClient::MySqlCommand(sql, Connection);
MySql::Data::MySqlClient::MySqlDataReader^ dataReader = command->ExecuteReader();

cbCsoportnev->Items->Clear();
while (dataReader->Read()){
cbCsoportnev->Items->Add(dataReader->GetString(0));
}
dataReader->Close();
Connection->Close();
}
}

private: System::Void cbStatusz_DropDown(System::Object^ sender, System::EventArgs^ e)
{
if (Connection->State == ConnectionState::Closed)
{
Connection->Open();
String^ sql = "SELECT statusznev From cikkstatusz";

MySql::Data::MySqlClient::MySqlCommand^ command = gcnew MySql::Data::MySqlClient::MySqlCommand(sql, Connection);
MySql::Data::MySqlClient::MySqlDataReader^ dataReader = command->ExecuteReader();

cbCsoportnev->Items->Clear();
while (dataReader->Read()){
cbStatusz->Items->Add(dataReader->GetString(0));
}
dataReader->Close();
Connection->Close();
}
}

private: System::Void BongeszoGridView_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
try{
Cursor->Current = Cursors::WaitCursor;
DataGridViewRow^ selectIndex = BongeszoGridView->CurrentRow;
int Index = selectIndex->Index;
if(e->KeyCode == Keys::PageDown || e->KeyCode == Keys::Down)
if(Index==99)
{
from += 100;
if (eredm<=100)
{
meddig=0;
}
if (eredm>100)
{
meddig = eredm-100;
}
if (from>meddig)
{
from=meddig;
}

this->dataSet = gcnew System::Data::DataSet();
BongeszoGridView->DataSource = this->dataSet;
BongeszoGridView->DataMember = String::Empty;

szures();

this->BongeszoCommand->Connection = this->Connection;
this->dataSet->EnforceConstraints = false;
BongeszoDataAdapter->Fill(dataSet, "Table");
BongeszoGridView->DataMember = "Table";

}
if(e->KeyCode == Keys::PageUp || e->KeyCode == Keys::Up)
if(Index==0 && from>0)
{
from -= 100;

if (from<=0)
{
from=0;
}
this->dataSet = gcnew System::Data::DataSet();
BongeszoGridView->DataSource = this->dataSet;
BongeszoGridView->DataMember = String::Empty;

szures();

this->BongeszoCommand->Connection = this->Connection;
this->dataSet->EnforceConstraints = false;
BongeszoDataAdapter->Fill(dataSet, "Table");
BongeszoGridView->DataMember = "Table";
}
Cursor->Current = Cursors::Default;
}
catch (MySql::Data::MySqlClient::MySqlException^ exception)
{
MessageBox::Show(exception->Message,"Hiba! Lpjen kapcsolatba a rendszergazdval!");
}
}

void szures()
{
this->BongeszoCommand->CommandText =L"SELECT \n"+
L"COALESCE(keszlet.raktar,'"+cbRaktar->Text+"') AS Rakt,\n"+
L"cikk.cikk AS Cikk,\n"+
L"cikktonus.cikktonus AS Tnus,\n"+
L"cikk.gyarikod AS 'Sz.Cikk',\n"+
L"cikk.gyaritetel AS 'Sz.ttel',\n"+
L"cikkcsoport.cikkcsoportnev AS Csoprtnv,\n"+
L"cikk.cikkcsalad AS Csaldnv,\n"+
L"cikk.cikknev AS Cikkneve,\n"+
L"cikk.tulajdonsag AS Mret,\n"+
L"keszlet.mennyiseg AS Kszlet, \n"+
L"ROUND(arakt.kisker_ar*1.2) AS 'Egys.r' \n"+
L"FROM \n"+
L"keszlet \n"+
L"LEFT OUTER JOIN cikktonus ON (keszlet.cikktonus = cikktonus.cikktonus) \n"+
L"LEFT OUTER JOIN cikk ON (cikk.cikk = cikktonus.cikk) \n"+
L"AND (keszlet.cikk = cikk.cikk) \n"+
L"LEFT OUTER JOIN cikkcsoport ON (cikk.cikkcsoport = cikkcsoport.cikkcsoport) \n"+
L"LEFT OUTER JOIN `arakt` ON (cikk.cikk = `arakt`.cikk) \n"+
L"WHERE \n"+
L"(keszlet.raktar = '"+cbRaktar->Text+"') AND \n"+
L"(cikk.cikk LIKE '"+tbCikk->Text+"%') AND \n"+
L"(cikk.gyarikod LIKE '"+tbSzCikk->Text+"%') AND \n"+
L"(cikk.gyaritetel LIKE '"+tbSztetel->Text+"%') AND \n"+
L"(cikkcsoport.cikkcsoportnev LIKE '"+cbCsoportnev->Text+"%') AND \n"+
L"(cikk.cikkcsalad LIKE '"+tbCsaladnev->Text+"%') AND \n"+
L"(cikk.cikknev LIKE '"+tbCikknev->Text+"%') AND \n"+
L"(cikk.tulajdonsag LIKE '"+tbMeret->Text+"%') AND \n"+
L"(cikk.statusz LIKE '"+cbStatusz->Text+"%') LIMIT "+from+",100";

}

void count()
{
String^ sql = L"SELECT COUNT(*) \n"
L"FROM \n"+
L"keszlet \n"+
L"LEFT OUTER JOIN cikktonus ON (keszlet.cikktonus = cikktonus.cikktonus) \n"+
L"LEFT OUTER JOIN cikk ON (cikk.cikk = cikktonus.cikk) \n"+
L"AND (keszlet.cikk = cikk.cikk) \n"+
L"LEFT OUTER JOIN cikkcsoport ON (cikk.cikkcsoport = cikkcsoport.cikkcsoport) \n"+
L"LEFT OUTER JOIN `arakt` ON (cikk.cikk = `arakt`.cikk) \n"+
L"WHERE \n"+
L"(keszlet.raktar = '"+cbRaktar->Text+"') AND \n"+
L"(cikk.cikk LIKE '"+tbCikk->Text+"%') AND \n"+
L"(cikk.gyarikod LIKE '"+tbSzCikk->Text+"%') AND \n"+
L"(cikk.gyaritetel LIKE '"+tbSztetel->Text+"%') AND \n"+
L"(cikkcsoport.cikkcsoportnev LIKE '"+cbCsoportnev->Text+"%') AND \n"+
L"(cikk.cikkcsalad LIKE '"+tbCsaladnev->Text+"%') AND \n"+
L"(cikk.cikknev LIKE '"+tbCikknev->Text+"%') AND \n"+
L"(cikk.tulajdonsag LIKE '"+tbMeret->Text+"%') AND \n"+
L"(cikk.statusz LIKE '"+cbStatusz->Text+"%')";

MySql::Data::MySqlClient::MySqlCommand^ command = gcnew MySql::Data::MySqlClient::MySqlCommand(sql, Connection);
MySql::Data::MySqlClient::MySqlDataReader^ dataReader;

if (Connection->State == ConnectionState::Closed)
{
Connection->Open();
dataReader = command->ExecuteReader();
while (dataReader->Read()){
eredm = dataReader->GetInt32(0);
}
}
dataReader->Close();
Connection->Close();
}
#pragma endregion
};
}
aspirany
 
Posts: 12
Joined: Mon 04 Sep 2006 16:51

Postby Alexey » Tue 17 Oct 2006 07:39

You use Connector/NET provider by MySQL AB. But this is the forum of MySQLDirect .NET. MySQLDirect .NET is data provider to direct access to MySQL database server for the Microsoft .NET Framework and .NET Compact Framework. Key features of MySQLDirect .NET are listed here. You can download free evaluation version here. Installation package includes required assemblies, full help system and various sample projects in C#, MC++, VB.NET, Delphi.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

with corelab::mysql same problem

Postby aspirany » Tue 17 Oct 2006 14:30

I know this mysqlab .net ,but i have same problem with mysql corelab and my trial period over couple days ago.

I don't know what is the problem with two datareader.

Thanks your help!
aspirany
 
Posts: 12
Joined: Mon 04 Sep 2006 16:51

Postby Alexey » Tue 17 Oct 2006 14:58

Please sent me an appropriate sample project (AlexeyI at crlab dot com).
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for MySQL