Connecting Tech Pros Worldwide Forums | Help | Site Map

problem with updating text from textbox in database

Eric
Guest
 
Posts: n/a
#1: Oct 23 '08
Hi,

There is a textbox which contains some text.
The purpose is to update the text manually into the textbox and send
(update) the updated text to the database.

My problem is that when i click on button2, variable 'txt' contains the
original text and not the manually updated text.

I must forget something but can't find it right now.
Thanks for help
Eric

in aspx file:
<asp:TextBox ID="TextBox1" TextMode="MultiLine"
runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="update text" />

in code-behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
TextBox1.Text = "this is the not updated text"

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim txt As String
txt = TextBox1.Text

Using mConnection As New SqlConnection(param.ConnectionString)
mConnection.Open()
sql = "update mytable set n1 =@txt"
comd = New SqlCommand(sql, mConnection)
comd.Parameters.AddWithValue("@txt", txt)
comd.ExecuteNonQuery()
End Using



Lloyd Sheen
Guest
 
Posts: n/a
#2: Oct 23 '08

re: problem with updating text from textbox in database


Eric wrote:
Quote:
Hi,
>
There is a textbox which contains some text.
The purpose is to update the text manually into the textbox and send
(update) the updated text to the database.
>
My problem is that when i click on button2, variable 'txt' contains the
original text and not the manually updated text.
>
I must forget something but can't find it right now.
Thanks for help
Eric
>
in aspx file:
<asp:TextBox ID="TextBox1" TextMode="MultiLine"
runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="update text" />
>
in code-behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
TextBox1.Text = "this is the not updated text"
>
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim txt As String
txt = TextBox1.Text
>
Using mConnection As New SqlConnection(param.ConnectionString)
mConnection.Open()
sql = "update mytable set n1 =@txt"
comd = New SqlCommand(sql, mConnection)
comd.Parameters.AddWithValue("@txt", txt)
comd.ExecuteNonQuery()
End Using
>
>
In the page load you are reseting the text every time. Put in a check
for a postback (IsPostBack) and set the text only when it is not a postback.

LS
Eric
Guest
 
Posts: n/a
#3: Oct 24 '08

re: problem with updating text from textbox in database


Thanks

"Lloyd Sheen" <a@b.cschreef in bericht
news:%23JtvNtVNJHA.2824@TK2MSFTNGP06.phx.gbl...
Quote:
Eric wrote:
Quote:
>Hi,
>>
>There is a textbox which contains some text.
>The purpose is to update the text manually into the textbox and send
>(update) the updated text to the database.
>>
>My problem is that when i click on button2, variable 'txt' contains the
>original text and not the manually updated text.
>>
>I must forget something but can't find it right now.
>Thanks for help
>Eric
>>
>in aspx file:
><asp:TextBox ID="TextBox1" TextMode="MultiLine"
>runat="server"></asp:TextBox>
><asp:Button ID="Button2" runat="server" Text="update text" />
>>
>in code-behind:
>Protected Sub Page_Load(ByVal sender As Object, ByVal e As
>System.EventArgs) Handles Me.Load
>TextBox1.Text = "this is the not updated text"
>>
>Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
>System.EventArgs) Handles Button2.Click
>Dim txt As String
>txt = TextBox1.Text
>>
>Using mConnection As New SqlConnection(param.ConnectionString)
>mConnection.Open()
>sql = "update mytable set n1 =@txt"
>comd = New SqlCommand(sql, mConnection)
>comd.Parameters.AddWithValue("@txt", txt)
>comd.ExecuteNonQuery()
>End Using
>
In the page load you are reseting the text every time. Put in a check for
a postback (IsPostBack) and set the text only when it is not a postback.
>
LS

Closed Thread