Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#带数据库mysql工作台_C#_Mysql - Fatal编程技术网

c#带数据库mysql工作台

c#带数据库mysql工作台,c#,mysql,C#,Mysql,我使用mysql workbench 5.2ce 我的数据库中的Im 2列(teble hm)第一列(num int(10)),第二列(messagev varchar(255))此代码不工作。请输入解决方案?没有带点的表名。将其保留为数据库名称引用。如果没有这些额外的混乱,事情已经够棘手的了 如有疑问,请在表名周围加上回勾 private void button1_Click(object sender, EventArgs e) { try

我使用mysql workbench 5.2ce
我的数据库中的Im 2列(teble hm)第一列(num int(10)),第二列(messagev varchar(255))此代码不工作。请输入解决方案?

没有带点的表名。将其保留为数据库名称引用。如果没有这些额外的混乱,事情已经够棘手的了

如有疑问,请在表名周围加上回勾

 private void button1_Click(object sender, EventArgs e)
        {
          try
            {
                string strInsert = "INSERT INTO data.hm(num, messagev) VALUES('"               +textBox1.Text + "', '" + textBox2.Text + "');";
                cmd = new MySqlCommand(strInsert, connection);
                connection.Open();
                cmd.ExecuteNonQuery();
                connection.Close();
                MessageBox.Show("yes", "test");
                this.Close();
            }
            catch
            {
                MessageBox.Show("not", "test");
            }

        }
错误代码:1049。未知数据库“this”

--成功

错误代码:1146。“this.hm”表不存在

--成功

异常处理 至少在开发阶段,不要覆盖异常信息,而不是自行生成的无用错误消息。展示一些有用的东西

insert into `this.hm` (id) values(7);

删除try/catch块并显示异常消息。然后在这里写下什么是错误消息?我们可以在表名中有点吗?我们假设您有一个名为dbname
data
的模式,其中一个表名为
hm
。更正,我假设您的表名周围有背景标记
data.hm
。我可以让它工作。但我建议不要用带点的表名
create table `this.that`
(   id int not null
);
insert into this.hm (id) values(7);
insert into `this.hm` (id) values(7);
catch (MySqlException ex)
{   Console.WriteLine("Error: {0}", ex.ToString());
}