Click here to Skip to main content
13,457,673 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have some textboxes and a submit button.
I am able to retrieve data from database and shown them to the textboxes
I want to update this data and then to save them back to the database.
How can I do that?
What code should I use in the click handler of the button?
Posted 14-Nov-12 1:30am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

As you are saying you have successfully shown the data on textboxes and now you are trying to update same data, ok for that you have need to store any Primary Key value of particular row or shown data and store that value in Viewstate or session, after that on Button_Click you can get the value of all the textboxes and update the database by the stored value in the viewstate or sassion.

you can also store the Primary Key value in the Hidden Field or you can use query string also on the place of viewstate or sassion.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Retrieve your primary key value in Session varaibles and then write the following code in updatebtn_click

Protected void updatebtn_Click(object sender, EventArgs e)

SqlCommand cmd= new SqlCommand("Update TableName Set Column1=@Column1,Column2=@Column2 Where ID=@ID",Conn);
//Conn is SqlConnection object that You have created.

Catch(Exception exp)
throw exp;

Hope, It will help you.
ro1 15-Nov-12 5:44am
How can I retrieve the primary key value in session varaibles?
Sorry for my question but i am new at programming
faisal23 15-Nov-12 5:52am
You are fetching data successfully from database as you said. So you supply some id or primary key on the basis of which you are able to fetch data right. So at the time of updation use same key to update particular record...
ro1 15-Nov-12 6:46am
I retrieve data from the database using this code:
Dim con As New OleDb.OleDbConnection
Dim strCon As String = "Provider=SQLOLEDB; Data Source=; Initial Catalog=; User ID=; Password="

con.ConnectionString = strCon

Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter

Sql = "SELECT * FROM Tablename"

da = New OleDb.OleDbDataAdapter(Sql, conn)
da.Fill(ds, "Tablename")
txtid.Value = ds.Tables("Tablename").Rows(inc).Item("2")

And then i navigate through records of te table using navigator buttons first,.. last.
I dont know now how to specify in which record I am in a specific moment(primary key) and then to update that record?
_Raj sinha 16-Nov-12 5:38am
Are you developing a Windows Application or Web Application? Tell me first
_Raj sinha 16-Nov-12 5:51am
If you are using windows app and retrieving the Primary key value on textbox then use the above solution that i have updated now. The code is in C#, you can convert it to VB
Hope it works..
lovitaxxx 16-Nov-12 6:29am
I am developing a web app
_Raj sinha 16-Nov-12 6:37am
ok, the above given code will work if you are retrieving the Id(Primary key) in textbox.
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

I think knowing the basic ADO.NET will enable you to do this and all DB operations very very easily. Here is a link that will definitely help you:

A Beginner's Tutorial for Understanding ADO.NET[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02-2016 | 2.8.180322.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100