DbCommand不包含ExecuteReader的定义

时间:2015-06-08 18:07:19

标签: c# mysql

我使用以下数据库访问代码会引发编译时错误:

private void button2_Click(object sender, EventArgs e)
    {
        string constring  = "datasource=localhost; port=3306;username=root;password=root";

        string Query = "insert into endocrine.edata(Id,Name,Surname,Age,duration) values('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "','" + this.textBox4.Text + "','" + this.textBox5.Text + "');";


        MySqlConnection conDataBase  = new MySqlConnection(constring);

        MysqlCommand cmdDataBase = new MysqlCommand(Query, conDataBase);

        MySqlDataReader myReader;
        {

        try
        {
            conDataBase.Open();
            myReader = cmdDataBase.ExecuteReader();
            MessageBox.Show("Saved");
            while (myReader.Read())
            {
            }
            conDataBase.Close();

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);

我收到以下错误。

error

0 个答案:

没有答案