Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.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,我在Visual Studio C#2010 Express中工作,在使用mySQL数据库时遇到一些问题 我已经实现了连接按钮,因此在您填写所有帐户信息(服务器、用户、端口和密码)后,单击连接按钮,将显示数据库列表,以及每个数据库中的表(当您选择特定数据库时),以及每个表中的数据(当您选择特定表时) 现在,我正在尝试实现插入、更新和删除按钮,但不知道从何处开始,我主要混淆了插入按钮(我的意思是不同的表有不同的列数,等等…)和我无法想象当单击插入按钮时它是如何工作的。有人可以给我一些建议或代码示例

我在Visual Studio C#2010 Express中工作,在使用mySQL数据库时遇到一些问题

我已经实现了连接按钮,因此在您填写所有帐户信息(服务器、用户、端口和密码)后,单击连接按钮,将显示数据库列表,以及每个数据库中的表(当您选择特定数据库时),以及每个表中的数据(当您选择特定表时)

现在,我正在尝试实现插入、更新和删除按钮,但不知道从何处开始,我主要混淆了插入按钮(我的意思是不同的表有不同的列数,等等…)和我无法想象当单击插入按钮时它是如何工作的。有人可以给我一些建议或代码示例,这样我就可以继续下去了


谢谢大家!

您或许可以看看下面的内容

我会使用一些SQL命令来执行插入/更新/删除等操作

有关mySQL SQL语法,请参见以下内容


转到:13.2。数据操作语句

如果您能找到一种方法将新记录输入网格的最后一行,您可以像这样手工创建一个查询

cmd.CommandText = "insert into " + listTables.Items[listTables.SelectedIndex].ToString() + "(";

foreach( var col in dataGridTableView.DataSource.DataTable[0].Columns)
    cmd.CommandText += col.ColumnName +  "," ;

// trim last comma off

cmd.CommandText += ") Values( ";

// access newly created row
// iterate over the cells of the row, and add values to the command text we've been building
// execute command text.

是的,我可以在表格的最后一行输入单词,你能提供一个带有注释的详细代码,这样我就能理解你在做什么吗?我真的很感激。
cmd.CommandText = "insert into " + listTables.Items[listTables.SelectedIndex].ToString() + "(";

foreach( var col in dataGridTableView.DataSource.DataTable[0].Columns)
    cmd.CommandText += col.ColumnName +  "," ;

// trim last comma off

cmd.CommandText += ") Values( ";

// access newly created row
// iterate over the cells of the row, and add values to the command text we've been building
// execute command text.