how to save from textbox

  • Thread starter Thread starter jaYPee
  • Start date Start date
J

jaYPee

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
 
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?
 
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?

i have already bind the textbox from databindings properties under
text row. and use this code to update the dataset

SqlDataAdapter1.Fill(DsStudentCourse1)
SqlDataAdapter2.Fill(DsStudentCourse1)
SqlDataAdapter3.Fill(DsStudentCourse1)

SqlDataAdapter 2 and 3 save the dataset from datagrid control but when
i edit the textbox control in my form including the datagrid the
textbox is not updated.
 
ADO.NET is a disconnected archatecture, unlike previous ADO versions... you
must preform the .Update() method on the data adapter to push any changes
back to the sql server.
 
ADO.NET is a disconnected archatecture, unlike previous ADO versions... you
must preform the .Update() method on the data adapter to push any changes
back to the sql server.

sorry but i have paste the wrong information instead of update the
code i have paste is fill.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
SqlDataAdapter1.Update(DsStudentCourse1)
SqlDataAdapter2.Update(DsStudentCourse1)
SqlDataAdapter3.Update(DsStudentCourse1)
End Sub

this is the code to update the dataset
 
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.SelectedIndex),
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
 
Back
Top