我错过了明显的吗?我想我将不得不在这里使用 ispostback 但不了解如何

Am I missing the obvious ? I think I will have to use ispostback here but not understanding how

我正在尝试使用更新查询将文件路径插入 SQL 服务器。但是,尽管查询 运行 成功且没有错误,但我无法看到更改。这是我的 asp.net 网络应用程序的代码。我试图在我的数据库中的 table 列中插入流值,在本地机器上执行此操作,

protected void Uplad(object sender, EventArgs e)
    {
        string phone = Session["phn"].ToString();
        string base64 = Request.Form["imgCropped"];
        byte[] bytes = Convert.FromBase64String(base64.Split(',')[1]);
        using (FileStream stream = new FileStream(Server.MapPath("~/Images/dp/" + phone + ".png"), FileMode.Create))
        {
            str = stream.ToString(); 
            con.Open();
            SqlCommand dpcmd = new SqlCommand("update xyz set ab = '" + str + "' where Moile ='" + phone + "'", cnn); //if i mouseover i can see the value of stream as C://xyz.png (cant write full path here) but when i check in db it is not showing up...
            stream.Write(bytes, 0, bytes.Length);
            stream.Flush();
            con.Close();
        }

        display.Visible = false;
    }

我在编译时也能看到值,文件也保存到指定的文件夹,但为什么数据库没有更新?它只取旧值吗?如何在 isPostback 中相应地实施更改?提前谢谢你:)

protected void Page_Load(object sender, EventArgs e)
    {


        try
        {

            if (!IsPostBack) // this block doesnt get executed when above handler is executed...hence i am assigning a value in the else to test
            {
                string phone = Convert.ToString(Session["pn"]);
                oldbi.Text = phone; //old number 
                usrname.Text = Convert.ToString(Session["fname"]); //assigning the name
                nm = Convert.ToString(Session["paw"]);
                if (phone != "")
                {
                    SetInitialRow();
                }
                else
                {
                    Response.Redirect("join.aspx");
                }

            }
            else
            {
                str = "do"; // i tried to assign a value here and i tried inserting this value in update statement but even this is not showing up in DB. I think it is not updating new value
            }
        }
        catch
        {
            Response.Redirect("join.aspx");
        }
    }

您还需要放置以下几行。 您所做的只是创建了一个 SqlCommand,但您还没有针对 connection.

执行它
dpcmd.CommandType=CommandType.Text;
dpcmd.ExecuteNonQuery();

更新

如果您只想保存文件名,那么这可能会有所帮助

string str=phone + ".png";
SqlCommand dpcmd = new SqlCommand("update xyz set ab = '" + str + "' where Mobile ='" + phone + "'", cnn);