更新C#wpf中的多个记录有什么问题 [英] update multiple records in C# wpf what is wrong in it

查看:75
本文介绍了更新C#wpf中的多个记录有什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void save_click(object sender,RoutedEventArgs e)

{

if(editbtn.IsChecked == true)

{

DataRowView acc =(DataRowView)cashaccnt.SelectedValue;

DataRowView acc2 =(DataRowView)contraacc.SelectedValue;



// string valu = contraacc.SelectedItem as string;



if(contraacc.Text!=&& cashaccnt.Text!=)

{

int a = Convert.ToInt32(textBox1.Text);



string updt1 =update cashrec1 set ref_date =' + dateset(masktxt.Text)+',cashacc ='+ cashaccnt.Text +',recefrom ='+ textBox4.Text +'where ref_no =+ a;







//字符串update2 =更新cashrec2 set con_acc ='+ contraacc.Text.ToString()+',desc1 ='+ textBox5.T ext.ToString()+',amount ='+ textBox6.Text +'where ref_no =+ textBox1.Text;

// updaterecord(update2);

$ b



for(int i = 0; I< datagrid1.items.count;我++盐{$ / $
string update2 =update cashrec2 set con_acc ='+((DataRowView)dataGrid1.Items [i])。Row +',desc1 ='+((DataRowView)dataGrid1.Items [i])。Row +',amount ='+((DataRowView)dataGrid1.Items [i])。Row +'where ref_no =+ textBox1.Text;

updaterecord(更新2);

}





MessageBox.Show(记录成功更新);

// count = count + 1;

}

else {MessageBox.Show(no value selected); }

}

private void save_click(object sender, RoutedEventArgs e)
{
if (editbtn.IsChecked == true )
{
DataRowView acc = (DataRowView)cashaccnt.SelectedValue;
DataRowView acc2 = (DataRowView)contraacc.SelectedValue;

//string valu = contraacc.SelectedItem as string;

if (contraacc.Text!="" && cashaccnt.Text!="")
{
int a = Convert.ToInt32(textBox1.Text);

string updt1 = "update cashrec1 set ref_date='" + dateset(masktxt.Text) + "',cashacc='" + cashaccnt.Text + "',recefrom='" + textBox4.Text + "' where ref_no=" + a;



//string update2 = "update cashrec2 set con_acc='" + contraacc.Text.ToString() + "' ,desc1='" + textBox5.Text.ToString() + "',amount='" + textBox6.Text + "' where ref_no=" + textBox1.Text;
//updaterecord(update2);



for (int i = 0; i<datagrid1.items.count;i++> {
string update2 = "update cashrec2 set con_acc='" +((DataRowView)dataGrid1.Items[i]).Row + "' ,desc1='" + ((DataRowView)dataGrid1.Items[i]).Row + "',amount='" + ((DataRowView)dataGrid1.Items[i]).Row + "' where ref_no=" + textBox1.Text;
updaterecord(update2);
}


MessageBox.Show("Record Updated Sucessfully");
//count = count + 1;
}
else { MessageBox.Show("no value selected"); }
}

推荐答案

它出了什么问题



嗯......让我们从SQL注入开始。

不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。改为使用参数化查询。



很可能会解决您的问题,但如果没有,您将需要查看 updaterecord 查看调试器中发生的事情的方法。
"what is wrong in it"

Well...let's start with SQL injection.
Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

Chances are that that will cure your problem, but if it doesn't, you will need to look at your updaterecord method to see what is happening in the debugger.


这篇关于更新C#wpf中的多个记录有什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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