Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update database row with texbox value changes 1

Status
Not open for further replies.

gi11ies

Programmer
Mar 26, 2002
52
Hi, I have a web page with textboxes on it that are populated from calling the database in the Page_Load, and I want to be able to update the row in the database from changes to these values in the textboxes when I click the update button.

In my code it works fine if I hard code a value into the sql, ie (employee_first='John') but (employee_first='" + firstName.Text + ") will not work at all, it wont take the changes values in the text boxes and update the database with them.

The code I use for the update button is:

Private Sub btnUpdate ( ByVal sender as System.Object, ByVal e as EventArgs )
Dim ctEmpConn As OleDbConnection
Dim ctConn1 As String
ctConn1 = ConfigurationSettings.AppSettings("connString1")
ctEmpConn = New OleDbConnection(ctConn1)
ctEmpConn.Open
Dim ctEmpSQL as String = "update employees set employee_first='" + firstName.Text + "', employee_last='" + lastName.Text + "' where employee_id=1"
Dim ctEmpCmd as New OleDbCommand(ctEmpSQL, ctEmpConn)
ctEmpCmd.ExecuteNonQuery()
ctEmpConn.Close
End Sub

Any Help with this would be great.

Gillies
 
Thanks - tried that, but didnt work ... just tried again just now, but still did not work.
 
I removed my Page_Load code, and if I enter
values into the database, it works great.

So the problem is lying in where I connect to the database, which is done the pretty standard way

set up conection from web.config
declare sql statement
execute it
create a data set from the result
assign the returned values to the text boxes (which is done in the following way)

firstName.Text = ctEmpDS.tables("Employee").rows(0)("employee_first").tostring()

can anyone see a problem here?
 
Page_Load:

If Not IsPostBack Then
'Fill your DataSet
End If
 
Thank you, very very much !!!!!!!!!!! Working through it today, I was using PostBack, but just could not get it to work - I forgot about No IsPostBack.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top