如何在一列中追加两个字段 [英] how to append two fields in one column

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

问题描述

您好先生/女士

我试图在列中添加一些数据并使用给定的代码...

 < span class =code-keyword> string  query1 =   update arms_records set renewal_dates ='hii'& ; renewal_dates,其中thana ='Hkksik'和licence_number ='6652'; 

string query2 = update arms_records set renewal_dates =' + dateTimePickerRenewDate.Value.ToString()+ '& renewal_dates where thana =' + comboBoxthana.SelectedText + '和licence_number =' + textBoxLicence_number .Text + ';



虽然我使用query1它工作,数据被附加和保存。

但我想使用查询2.但没有任何东西保存在数据库中。

谢谢...

解决方案

 tring query2 =   update arms_records set renewal_dates = + dateTimePickerRenewDate.Value.ToString()+  & renewal_dates where than = + comboBoxthana.SelectedText +  和licence_number = + textBoxLicence_number。 文本; 


创建查询字符串时不要使用字符串连接。它会让您打开sql注入攻击,为你创建额外的工作,使你的查询笨拙和难以调试。



使用参数代替 - http://www.dotnetperls.com/sqlparameter [ ^ ]



然后按照Sibasis05的建议进行操作 - 调试代码并检查 comboBoxthana.SelectedText textBoxLicence_number.Text 实际上包含一些数据。还要检查数据是否与表中的记录实际匹配 - 注意拼写错误和资本错误上

Hello sir/madam
I am trying to append some data in a column and using the given code...

string query1 = "update arms_records set renewal_dates= 'hii' & renewal_dates where thana='Hkksik' and licence_number='6652'";

 string query2 = "update arms_records set renewal_dates='" + dateTimePickerRenewDate.Value.ToString() + "' & renewal_dates where thana='" + comboBoxthana.SelectedText +"' and licence_number='" + textBoxLicence_number.Text + "'";


while I use query1 it works and data is appended and saved.
but i want to use query 2. but nothing is saved in database.
Thank you ...

解决方案

tring query2 = "update arms_records set renewal_dates=" + dateTimePickerRenewDate.Value.ToString() + " & renewal_dates where thana=" + comboBoxthana.SelectedText +"and licence_number=" +textBoxLicence_number.Text ;


Don't use string concatenation when creating your query string. It leaves you open to sql injection attacks, creates extra work for you and makes your query unwieldy and difficult to debug.

Use Parameters instead - http://www.dotnetperls.com/sqlparameter[^]

Then do as Sibasis05 has suggested - debug your code and check that comboBoxthana.SelectedText and textBoxLicence_number.Text actually contain some data. Also check that the data actually matches to a record in your table - watch out for spelling mistakes and capitalisation


这篇关于如何在一列中追加两个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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