By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

how to save from textbox

P: n/a
anyone know how to save record that is encoded from a textbox back to
sql server 2000? i know how to display a record from sql server to
textbox but don't know how to save the changes i made.

thanks in advance
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

One way would be to use DataTable as datasource, load data there, bind
textbox to it and after editing call DataAdapter.Update method.
Anyway, how are you doing it now?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"jaYPee" <hi******@yahoo.com> wrote in message
news:9q********************************@4ax.com...
anyone know how to save record that is encoded from a textbox back to
sql server 2000? i know how to display a record from sql server to
textbox but don't know how to save the changes i made.

thanks in advance

Nov 20 '05 #2

P: n/a
Hi there, I have the exact same frustration except with webforms....

http://www.15seconds.com/issue/030604.htm

I found this hope it helps a bit! Also download the visual basic .net
resource kit it has some examples exactly for what your talking about as
well.

Private Sub UpdateProduct()

' This sub is used to update and existing record with values

' from the form.

Dim cnSQL As SqlConnection

Dim cmSQL As SqlCommand

Dim strSQL As String

Dim intRowsAffected As Integer

' Validate form values.

If Not IsValidForm() Then

Exit Sub

End If

Try

' Build update statement to update product table with data

' on form.

strSQL = "UPDATE Products SET" & _

" ProductName = " & PrepareStr(txtProductName.Text) & _

" ,QuantityPerUnit = " & PrepareStr(txtQtyPerUnit.Text) & _

" ,UnitPrice = " & txtUnitPrice.Text & _

" ,UnitsInStock = " & txtUnitsInStock.Text & _

" ,UnitsOnOrder = " & txtUnitsOnOrder.Text & _

" ,ReorderLevel = " & txtReorderLevel.Text & _

" ,SupplierID = " & CType(cbSuppliers.Items(cbSuppliers.SelectedIndex) ,
ListItem).ID & _

" ,CategoryID = " & CType(cbCategories.Items(cbCategories.SelectedInde x),
ListItem).ID & _

" ,Discontinued = " & CType(IIf(chkDiscontinued.Checked, "1", "0"), String)
& " " & _

"WHERE ProductID = " & CInt(txtProductID.Text)

cnSQL = New SqlConnection(ConnectionString)

cnSQL.Open()

cmSQL = New SqlCommand(strSQL, cnSQL)

intRowsAffected = cmSQL.ExecuteNonQuery()

If intRowsAffected <> 1 Then

MsgBox("Update Failed.", MsgBoxStyle.Critical, "Update")

End If

' Close and Clean up objects

cnSQL.Close()

cmSQL.Dispose()

cnSQL.Dispose()

Catch e As SqlException

MsgBox(e.Message, MsgBoxStyle.Critical, "SQL Error")

Catch e As Exception

MsgBox(e.Message, MsgBoxStyle.Critical, "General Error")

End Try

End Sub

Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRefresh.Click

PopulateCategoryCombo()

PopulateSupplierCombo()

PopulateProductList()

End Sub

"jaYPee" <hi******@yahoo.com> wrote in message
news:9q********************************@4ax.com...
anyone know how to save record that is encoded from a textbox back to
sql server 2000? i know how to display a record from sql server to
textbox but don't know how to save the changes i made.

thanks in advance

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.