当我更新网格视图时发生错误 [英] When i updating grid view error occurs

查看:99
本文介绍了当我更新网格视图时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void ResultGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
  TextBox txtFName = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtFName");
        TextBox txtLName = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtLName");
        TextBox txtCity = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtCity");
        TextBox txtState = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtState");
        TextBox txtCountry = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtCountry");
        TextBox txtDescription = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtDescription");
 
 cmd.Connection = con;
 cmd.CommandText = "Update Vendors Set VendorFName = '" + txtFName.Text + "',VendorLName = '" + txtLName.Text + "',VendorCity = '" + txtCity.Text + "',VendorState = '" + txtState.Text + "',VendorCountry = '" + txtCountry.Text + "',VendorDescription = '" + txtDescription.Text + "' where VendorId = " + ResultGridView.DataKeys[e.RowIndex].Values[0].ToString() + "";
        con.Open();
        cmd.ExecuteNonQuery();
        ResultGridView.EditIndex = -1;
        FillVendorGrid();
        con.Close();



从上面的错误是什么,请纠正它.

我发送了代码.请从我的代码中纠正



From the above what is the error please correct it.

i send the code.please correct from my code

推荐答案

您应该告诉我们错误是什么.我们没有您的应用程序,也没有您的数据库.您可以做几件事!

检查文本字段中是否都包含单引号.
调试应用程序并捕获Command.Text,然后尝试在SSMS中运行它以查找错误.

了解有关参数化查询的信息.
了解有关SQL注入的信息.

认识我的同伴Bobby Tables!
You are supposed to tell us what the error is. We do not have your application nor do we have your database. A couple of things you can do!

Check that the text fields all have enclosing single quotes.
Debug the app and capture the Command.Text and try and run it in SSMS to find the error.

Learn about paramterised queries.
Learn about SQL Injection.

Meet my mate Bobby Tables!


这篇关于当我更新网格视图时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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