Updating Database

Discussion in 'ASP .Net' started by Dot Net Daddy, Aug 14, 2006.

  1. Hello,

    I have some textareas assigned some values which is taken from the
    database on page_load. Also there is an update button.

    But when I change the text and click the update button it does not
    work. Actually it works, but the text I type in the textarea is not
    recognized. It recognizes the assigned value on page_load, and updates
    the same thing over itself.


    Here is my code:


    sqlDS.UpdateCommand = "UPDATE Blogs SET diaryHeader='" &
    TextBox1.Text.Replace("'", "''") & "', diaryInfo='" &
    TextBox2.Text.Replace("'", "''") & "', lastUpdate='" & Today.Now & "'
    WHERE userName='" & User.Identity.Name & "' AND diaryDate='" &
    Label4.Text & "'"
    sqlDS.Update()
    Label6.Text = "Great"


    Thanks in advance.
    Dot Net Daddy, Aug 14, 2006
    #1
    1. Advertising

  2. Does the Page_Load use If Not Page.IsPostBack Then?

    If not, you are resetting the form in Page_Load prior to your update button
    event.

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    *************************************************
    Think Outside the Box!
    *************************************************
    "Dot Net Daddy" <> wrote in message
    news:...
    > Hello,
    >
    > I have some textareas assigned some values which is taken from the
    > database on page_load. Also there is an update button.
    >
    > But when I change the text and click the update button it does not
    > work. Actually it works, but the text I type in the textarea is not
    > recognized. It recognizes the assigned value on page_load, and updates
    > the same thing over itself.
    >
    >
    > Here is my code:
    >
    >
    > sqlDS.UpdateCommand = "UPDATE Blogs SET diaryHeader='" &
    > TextBox1.Text.Replace("'", "''") & "', diaryInfo='" &
    > TextBox2.Text.Replace("'", "''") & "', lastUpdate='" & Today.Now & "'
    > WHERE userName='" & User.Identity.Name & "' AND diaryDate='" &
    > Label4.Text & "'"
    > sqlDS.Update()
    > Label6.Text = "Great"
    >
    >
    > Thanks in advance.
    >
    Cowboy \(Gregory A. Beamer\), Aug 15, 2006
    #2
    1. Advertising

  3. No I didn't use If Not Page.IsPostBack Then ...

    but I understand what you mean, however I couldnt get it into code. I
    am updating the database on Button.Click event.

    Maybe copying the same code in the Button_Click into Page_Load under
    If Page.IsPostback would work. But the problem is there is no way to
    access the page from the address bar. I mean the page is a cross page
    post back from another page. So it might cause problems.

    Actually would work in practice, but on first page load it updates
    itself, am I right?


    Cowboy (Gregory A. Beamer) wrote:
    > Does the Page_Load use If Not Page.IsPostBack Then?
    >
    > If not, you are resetting the form in Page_Load prior to your update button
    > event.
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > *************************************************
    > Think Outside the Box!
    > *************************************************
    > "Dot Net Daddy" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > I have some textareas assigned some values which is taken from the
    > > database on page_load. Also there is an update button.
    > >
    > > But when I change the text and click the update button it does not
    > > work. Actually it works, but the text I type in the textarea is not
    > > recognized. It recognizes the assigned value on page_load, and updates
    > > the same thing over itself.
    > >
    > >
    > > Here is my code:
    > >
    > >
    > > sqlDS.UpdateCommand = "UPDATE Blogs SET diaryHeader='" &
    > > TextBox1.Text.Replace("'", "''") & "', diaryInfo='" &
    > > TextBox2.Text.Replace("'", "''") & "', lastUpdate='" & Today.Now & "'
    > > WHERE userName='" & User.Identity.Name & "' AND diaryDate='" &
    > > Label4.Text & "'"
    > > sqlDS.Update()
    > > Label6.Text = "Great"
    > >
    > >
    > > Thanks in advance.
    > >
    Dot Net Daddy, Aug 15, 2006
    #3
  4. No, you were right. It works fine now in If Not Page.IsPostBack clause

    Thanks for your help...



    Dot Net Daddy wrote:
    > No I didn't use If Not Page.IsPostBack Then ...
    >
    > but I understand what you mean, however I couldnt get it into code. I
    > am updating the database on Button.Click event.
    >
    > Maybe copying the same code in the Button_Click into Page_Load under
    > If Page.IsPostback would work. But the problem is there is no way to
    > access the page from the address bar. I mean the page is a cross page
    > post back from another page. So it might cause problems.
    >
    > Actually would work in practice, but on first page load it updates
    > itself, am I right?
    >
    >
    > Cowboy (Gregory A. Beamer) wrote:
    > > Does the Page_Load use If Not Page.IsPostBack Then?
    > >
    > > If not, you are resetting the form in Page_Load prior to your update button
    > > event.
    > >
    > > --
    > > Gregory A. Beamer
    > > MVP; MCP: +I, SE, SD, DBA
    > >
    > > *************************************************
    > > Think Outside the Box!
    > > *************************************************
    > > "Dot Net Daddy" <> wrote in message
    > > news:...
    > > > Hello,
    > > >
    > > > I have some textareas assigned some values which is taken from the
    > > > database on page_load. Also there is an update button.
    > > >
    > > > But when I change the text and click the update button it does not
    > > > work. Actually it works, but the text I type in the textarea is not
    > > > recognized. It recognizes the assigned value on page_load, and updates
    > > > the same thing over itself.
    > > >
    > > >
    > > > Here is my code:
    > > >
    > > >
    > > > sqlDS.UpdateCommand = "UPDATE Blogs SET diaryHeader='" &
    > > > TextBox1.Text.Replace("'", "''") & "', diaryInfo='" &
    > > > TextBox2.Text.Replace("'", "''") & "', lastUpdate='" & Today.Now & "'
    > > > WHERE userName='" & User.Identity.Name & "' AND diaryDate='" &
    > > > Label4.Text & "'"
    > > > sqlDS.Update()
    > > > Label6.Text = "Great"
    > > >
    > > >
    > > > Thanks in advance.
    > > >
    Dot Net Daddy, Aug 15, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Boris Zakharin
    Replies:
    0
    Views:
    953
    Boris Zakharin
    Aug 4, 2003
  2. Tom Wild
    Replies:
    0
    Views:
    379
    Tom Wild
    Aug 21, 2003
  3. Chris D

    Updating Database Problem

    Chris D, Nov 20, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    347
    Chris D
    Nov 20, 2003
  4. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,370
    Carl Prothman [MVP]
    Jan 12, 2005
  5. news.rcn.com
    Replies:
    2
    Views:
    1,105
    Roedy Green
    Dec 10, 2007
Loading...

Share This Page