如何在mysql上的特定列中添加多个数据 [英] How To add multiple data into specific column on mysql

查看:77
本文介绍了如何在mysql上的特定列中添加多个数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#和mysql 1.1.4版的好日子。我希望有人可以帮助我如何将多个数据添加到TOname和nameTO我不知道在这么多试验后该怎么做。这里有可能代码。







查询=插入到tblrightofwayagreement(名称,PS,PS1, brgy,mun,nameTO,TOnum,dateofack)+值('+ txtname.Text +','+ cmbps.Text +','+ txtps.Text +','+ txtbrgy。 Text +','+ txtmun.Text +','+ txtto.Text +','+ txtpiece.Text +','+ txtack.Text +');

解决方案

如果要将多个文本框中的值添加到单个列中,那么只需连接字符串...下面就是示例,您可以添加实际需要的值。 />


注意使用String.Format,它使您可以轻松读取查询,而无需担心关闭所有引号并更容易复制到数据库进行测试。另请注意,正确的外壳使物体更具可读性。另外,使用全文而不是像brgy这样的快捷方式,你会感谢自己一年后回来并且不知道这意味着什么:)



回答你的问题是大胆的,其余的是免费教育。

Query = String.Format(INSERT INTO tblRightOfWayAgreement(Name,PS,PS1,brgy,mun,nameTO,TOnum,dateoffack)

VALUES('{0}',' {1} ','{2}','{3}','{4}',txtName.Text,< b> cmbps.Text +其他一些值,

txtPS.Text,

txtBrgy.Text,

txtMun。文字,

txtTO.Text,

txtPiece.Text,

txtAck.Text









现在解决方案已经完成:

我强烈建议您使用存储过程或者至少做一些事情来阻止 SQL注入 [ ^ ]

考虑如果我在txtName中输入以下内容会发生什么

';走; DROP TABLE tblRightOfWayAgreement; -



绝不信任用户输入!!



如果这有帮助请花时间接受解决方案

Good day to all i'm using C# and mysql version 1.1.4. i hope someone can help me on how to add multiple data into TOname and nameTO i don't know what to do after so many trials. here are may code.



Query = "Insert into tblrightofwayagreement(Name,PS,PS1,brgy,mun,nameTO,TOnum,dateofack)" + "values('" + txtname.Text + "','" + cmbps.Text + "','" + txtps.Text + "','" + txtbrgy.Text + "','" + txtmun.Text + "','" + txtto.Text + "','" + txtpiece.Text +"','" + txtack.Text + "')";

解决方案

If you want to add values from multiple textboxes into single column then you just concatenate the string...below is the example, you add the values you actually need.

Note the use of String.Format which enables you easy reading of the query without having to worry about closing all the quotes and easier copying into the database for testing. Note also that proper casing makes the thing more readable. Also, use full text instead of shortcuts like "brgy", you'll thank yourself in a year when you return and have no idea what that means :)

The answer to your question is bold, the rest is free education.
Query = String.Format("INSERT INTO tblRightOfWayAgreement (Name, PS, PS1, brgy, mun, nameTO, TOnum, dateoffack)
VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', txtName.Text, cmbps.Text + " some other value",
txtPS.Text,
txtBrgy.Text,
txtMun.Text,
txtTO.Text,
txtPiece.Text,
txtAck.Text
)



Now that the solution is done:
I STRONGLY SUGGEST you use stored procedure or at least do something to prevent SQL Injection[^]
Consider what would happen if I entered the following in txtName
'; GO; DROP TABLE tblRightOfWayAgreement; --

NEVER TRUST USER INPUT!!

If this helps please take time to accept the solution.


这篇关于如何在mysql上的特定列中添加多个数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆