473,508 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with updating text from textbox in database

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
Oct 23 '08 #1
2 3225
Eric wrote:
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
Oct 23 '08 #2
Thanks

"Lloyd Sheen" <a@b.cschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
Eric wrote:
>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

Oct 24 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
360
by: Brett | last post by:
Hello... Im having a problem getting a datagrid to update. Everything in my code looks ok so Im at a loss. I can click update and the grid will rebind... but not with my updated data. I am not...
3
1784
by: Jon Agiato | last post by:
Hi, I am trying to use a data grid in a web application in which I have three tiers. The DataGrid is not set up to a data source, or a data adapter, so everytime I make a change I send the cell...
5
2013
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
7
2206
by: Peter D.C. | last post by:
Hi I want to update data hold in several textbox controls on an asp.net form. But it seems like it is the old textbox values that is "re-updates" through a stored procedure who updates a SQL...
2
4533
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
23
1915
by: tanya2001 | last post by:
hi all.. I am trying to update my datagrid in my webform...but its not getting updated..though in the database it removing the <null> and inserting a blank field....its not taking the input which m...
11
6044
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
0
1641
by: John Mason | last post by:
Hi, I've been trying for most of the day to get a FormView control to work. I would like to display a single record, based on a unique user id (loginid), which I am retreiving from a cookie. No...
2
2611
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7383
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.