1.database.SqlString = "update kb_kcb set kch = '"+this.TextBox1.Text+"',kcm = '" + this.TxbKcm.Text + "', jsh = '" + this.TxbJsh.Text + "',jsm = '" + this.TxbJsm.Text + "' where kcid = " + this.GridView1.SelectedRow.Cells[5].Text;2.database.SqlString = "delete from kb_kcb where kcid = " + this.GridView1.SelectedRow.Cells[5].Text;这两个语句有问题换种方式:
DataRowView row = this.m_DataSet.Tables[0].DefaultView[this.dataGridView.CurrentRow.Index];string mysql = @"delete TyreUser where UserName=@UserName";SqlParameter pm;
pm = cmd.Parameters.Add("@UserName", SqlDbType.NVarChar, 50);
pm.Value = row["UserName"].ToString();
DataRowView row = this.m_DataSet.Tables[0].DefaultView[this.dataGridView.CurrentRow.Index];string mysql = @"delete TyreUser where UserName=@UserName";SqlParameter pm;
pm = cmd.Parameters.Add("@UserName", SqlDbType.NVarChar, 50);
pm.Value = row["UserName"].ToString();
解决方案 »
- C#树桩控件
- Winform如何获得当前选中的文本
- datagridview如何绑定List<>
- TakeWhile中的Lambda表达式
- dataset写入ACCESS
- [Winform] Process执行问题。谢谢
- iframe自适应高度的问题,特殊情况,大家指点一下。
- 疑问啊!
- MonthCalendar的问题,急,急,急(00分,大奉送)
- 请教各位:我的ComboBox 的DropDownstyle是DropDown,但将item添加进去以后,点击其中的一项,但Text只能高亮显示,但没有文字。(急,在
- 关于数据库连接问题!
- C#.net中DataGrid里面e.Item.ItemType如何用?
应改成:
database.SqlString = string.Format("update kb_kcb set kch= '{0}',kcm = '{1}',jsh = '{2}',jsm = '{3}' where kcid = '{4}'",
this.TextBox1.Text, this.TxbKcm.Text, this.TxbJsh.Text, this.TxbJsm.Text, this.GridView1.SelectedRow.Cells[5].Text其中:
database.SqlString = "delete from kb_kcb where kcid = " + this.GridView1.SelectedRow.Cells[5].Text;
应改成:
database.SqlString = string.Format("delete from kb_kcb where kcid = '{0}'", this.GridView1.SelectedRow.Cells[5].Text);
访问列最好用列名,而不要用索引,这样可以避免列顺序更改,还要修改代码以保持一致,同时可读性好.字符串拼接最好不要用+号,一是浪费性能,二是可读性差,不易排错.
建议使用string.Format()方法或StringBuilder类.