Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The CommandText property has not been properly initialized (MySqlDataReader)

Tags:

c#

database

mysql

The Reader is always null, I have no idea why.

Before the connection was in one method, everything worked fine.

Code:

private MySqlConnection connection;
private MySqlCommand command;
private MySqlDataReader Reader;

public Form1()
{
    InitializeComponent();
    DBint();
}
private void DBint()
{
    string myConnectionString = "SERVER=xxx;PORT=3306;" +
                                "DATABASE=xxx;" +
                                "UID=root;" +
                                "PASSWORD=xxx;";
    connection = new MySqlConnection(myConnectionString);
    command = connection.CreateCommand();
    MySqlDataReader Reader;//error occures her
    connection.Open();
    Reader = command.ExecuteReader();               
    //MessageBox.Show(tmp);                
    //connection.Close();    
}
like image 643
test123123 Avatar asked Sep 05 '11 13:09

test123123


1 Answers

You should set the CommandText property of the command object with your SELECT statement or stored procedure name, you cannot execute an empty command.

like image 85
Davide Piras Avatar answered Oct 11 '22 01:10

Davide Piras