开发者

How to insert using a control for MySQL and C#

Hello I need to know how to insert with mysql I have tried a couple different ways. I am using C# and Mysql here is an example of what I am trying to do(I already know this is incorrect but mybe you can get the idea of what I am trying to accomplish.)

MySqlCommand command = new MySqlCommand("INSERT INTO tbl_test (name) VALUES(").append(TextBox1.Text.ToString()).append(")"),conn);

PS sorry f开发者_运维技巧or not using the code editor couldn't figure it out thanks in advance.


You'll probably want something like this. I've written this from memory so there may be a few corrections needed to make it run.

var sql = "INSERT INTO tbl_test (name) VALUES (@name)";
var command = new MySqlCommand(sql, conn);
command.Parameters.AddWithValue("name", TextBox1.Text.ToString());
command.ExecuteNonQuery();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜