Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c中编辑gridview中的行#_C#_Mysql_Asp.net_Gridview - Fatal编程技术网

C# 在c中编辑gridview中的行#

C# 在c中编辑gridview中的行#,c#,mysql,asp.net,gridview,C#,Mysql,Asp.net,Gridview,在c#的一个GridView中,授权用户可以编辑MySql表上的单行 要编辑的参数有:number(int)、theAnnotation(char)和theUpload(FileUpload char) 我的问题是当要编辑的行已经包含在表的字段theUpload中的一个值时,例如: http://.../public/08072015.pdf 此值是您可以从中下载文件的位置,以前添加到此行中 如果在此行中尝试编辑字段number和theAnnotation的值,而不编辑字段theUpload,

在c#的一个GridView中,授权用户可以编辑MySql表上的单行

要编辑的参数有:
number
(int)、
theAnnotation
(char)和
theUpload
(FileUpload char)

我的问题是当要编辑的行已经包含在表的字段
theUpload
中的一个值时,例如:

http://.../public/08072015.pdf
此值是您可以从中下载文件的位置,以前添加到此行中

如果在此行中尝试编辑字段
number
theAnnotation
的值,而不编辑字段
theUpload
,因为该值存在,则更新查询将删除字段
theUpload
中存在的值

如何编辑GridView的行而不删除存储的信息

我不认为行中的每一个更改都需要重新加载同一个文件

请帮帮我,谢谢你

我的代码如下:

private void UpdateRow(
    string theNumber,
    string theAnnotation,
    string thefilename,
    string theID)
{
    string sql = String.Format(@"Update `UserTable` SET 
                                         theNumber = {0},                                              
                                         theAnnotation  = '{1}',
                                         thefilename = '{2}',
                                         WHERE ID = {3}; ",
                                    theNumber.ToString(),
                                    theAnnotation.ToString(),
                                    thefilename.ToString(),
                                    theID.ToString());
    using (OdbcConnection cn =
      new OdbcConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString))
    {
        using (OdbcCommand cmd = 
          new OdbcCommand(sql, cn))
        {
            cmd.Connection.Open();
            cmd.ExecuteNonQuery();
            gv.EditIndex = -1;
            BindData();
        }
    }
}



protected void gv_RowUpdating(Object sender, GridViewUpdateEventArgs e)
{
    string theID = gv.DataKeys[e.RowIndex].Value.ToString();
    GridViewRow row = gv.Rows[e.RowIndex];

    TextBox theNumber = (TextBox)row.FindControl("theNumber");
    TextBox theAnnotation = (TextBox)row.FindControl("theAnnotation");
    FileUpload thefilename = (FileUpload)row.FindControl("thefilename");

    theNumber1 = theNumber.Text;
    theAnnotation1 = theAnnotation.Text.ToString().Replace("'", "`");

    filename = Path.GetFileName(thefilename.PostedFile.FileName).ToString();
    FileExtention = System.IO.Path.GetExtension(thefilename.FileName);
    int fileSize = thefilename.PostedFile.ContentLength;

    if (fileSize > 0)
    {
        if (filename.ToString() != "")
        {
            if (FileExtention == ".pdf")
            {
                thefilename.SaveAs(Server.MapPath("public/" + filename.ToString()));
                filename = "http://.../public/" + filename.ToString();
            }
            else
            {
               ...
            }
        }
    }
    else
    {
        filename = "";
    }

    UpdateRow(theNumber1.ToString(), theAnnotation1.ToString(), filename.ToString(), ID.ToString());
}

请张贴您的code@Mainak:谢谢您的回复,我在第一个问题中添加了我的
代码。当您启动行编辑命令时会发生什么情况?我的意思是你的gridview行会发生什么情况?@Mainak:如果尝试编辑字段
theNumber
theAnnotation
的值,而不编辑字段
theUpload
,因为该值存在,更新查询会删除字段
theUpload
中存在的值。我看不出你的查询或你的代码有任何错误。因此,我建议在更新特定行之前,尝试读取值,特别是被删除的值(theUpload),并在更新行时在查询中包括cloumn的值(theUpload)。