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

santhoshkumar B

I am trying to insert file path into SQL Server with an update query. However, I am unable to see the changes despite query running successfully without errors. Here is the code of my asp.net web app. I am trying to insert the stream value in the column of table inside my database, doing this on local machine,

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;
    }

I am also able to see the values while compiling, file is also getting saved to the specified folder, but why is database not getting updated? Is it taking the old value only? How can I implement changes accordingly in isPostback? Thank you in advance :)

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");
        }
    }
Hemal

You need to place following lines also. What you have done is just created an SqlCommand, but you have not executed it against the connection.

dpcmd.CommandType=CommandType.Text;
dpcmd.ExecuteNonQuery();

UPDATE

If you just want to save filename, then this might help

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

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Wordpress "I think you have a wrond seperator"

분류에서Dev

I am trying to write a query but can seem to think of a way to do it

분류에서Dev

How can I get this code to make the sequence obvious?

분류에서Dev

How do I make it obvious which Firefox Profile is being used?

분류에서Dev

understanding and excel formula I have been using

분류에서Dev

Am I creating a usable custom page variable properly here?

분류에서Dev

Am I stupid or I just have a faulty USB drive?

분류에서Dev

If I have apply(i: Int), how can I have map?

분류에서Dev

Why is my VBA/SQL query say I am missing an operator?

분류에서Dev

NAT for a local device on pfSense - what am I missing?

분류에서Dev

Inherited Ubuntu server will not PING: What am I missing?

분류에서Dev

How do you get Python to open a text file using print and input? I have the code I am using below

분류에서Dev

Can I have an array that does not have a limit because I am getting my input by scanner?

분류에서Dev

I am trying to read a file and to show the reading progress in %. I have tried following code but I am not able to divide in chunks & show progress

분류에서Dev

How to search two tables sharing a foreign key (I think I'm asking this right....)?

분류에서Dev

I am on Manjaro, and I am setting it up for JDBC, I have installed mariadb, mariadb-jdbc but I am not able to locate the /etc/my.conf file

분류에서Dev

Do I have to use JSONP for API subdomain?

분류에서Dev

Do I have to use the localized version of a directory?

분류에서Dev

How can I tell which user limit I am running into?

분류에서Dev

How do I check whether I am using LVM?

분류에서Dev

How can I tell if I am out of inotify watches?

분류에서Dev

How i can use a criteria in cicle for i

분류에서Dev

Why is the output of this program not what I think

분류에서Dev

python regex not behaving as i think it should

분류에서Dev

How can i add a background image in the MainScreen menu (here)?

분류에서Dev

How Can I remove a marker from a Here Maps

분류에서Dev

Why am I able to run more concurrent threads than I have cpus?

분류에서Dev

I have to return a value from a function that is called multiple times and I am unable to do that

분류에서Dev

Why am I not being able to split a String in java given that I have a string containing filename?

Related 관련 기사

  1. 1

    Wordpress "I think you have a wrond seperator"

  2. 2

    I am trying to write a query but can seem to think of a way to do it

  3. 3

    How can I get this code to make the sequence obvious?

  4. 4

    How do I make it obvious which Firefox Profile is being used?

  5. 5

    understanding and excel formula I have been using

  6. 6

    Am I creating a usable custom page variable properly here?

  7. 7

    Am I stupid or I just have a faulty USB drive?

  8. 8

    If I have apply(i: Int), how can I have map?

  9. 9

    Why is my VBA/SQL query say I am missing an operator?

  10. 10

    NAT for a local device on pfSense - what am I missing?

  11. 11

    Inherited Ubuntu server will not PING: What am I missing?

  12. 12

    How do you get Python to open a text file using print and input? I have the code I am using below

  13. 13

    Can I have an array that does not have a limit because I am getting my input by scanner?

  14. 14

    I am trying to read a file and to show the reading progress in %. I have tried following code but I am not able to divide in chunks & show progress

  15. 15

    How to search two tables sharing a foreign key (I think I'm asking this right....)?

  16. 16

    I am on Manjaro, and I am setting it up for JDBC, I have installed mariadb, mariadb-jdbc but I am not able to locate the /etc/my.conf file

  17. 17

    Do I have to use JSONP for API subdomain?

  18. 18

    Do I have to use the localized version of a directory?

  19. 19

    How can I tell which user limit I am running into?

  20. 20

    How do I check whether I am using LVM?

  21. 21

    How can I tell if I am out of inotify watches?

  22. 22

    How i can use a criteria in cicle for i

  23. 23

    Why is the output of this program not what I think

  24. 24

    python regex not behaving as i think it should

  25. 25

    How can i add a background image in the MainScreen menu (here)?

  26. 26

    How Can I remove a marker from a Here Maps

  27. 27

    Why am I able to run more concurrent threads than I have cpus?

  28. 28

    I have to return a value from a function that is called multiple times and I am unable to do that

  29. 29

    Why am I not being able to split a String in java given that I have a string containing filename?

뜨겁다태그

보관