daniness
Well-known member
- Joined
- Feb 12, 2010
- Messages
- 49
- Programming Experience
- Beginner
Hi All,
I would appreciate your assistance with the following task: I'm trying to edit and save changes made to a row of a SQL table via Windows form textboxes. Right now when I run the app, I try to make a change to one of the textboxes, I click on the Save/Close button, but when I go to the database, the cell linked to the textbox is not showing the change.
Here is my code so far...please excuse the commented out code...I haven't gotten it to work correctly:
I would appreciate your assistance with the following task: I'm trying to edit and save changes made to a row of a SQL table via Windows form textboxes. Right now when I run the app, I try to make a change to one of the textboxes, I click on the Save/Close button, but when I go to the database, the cell linked to the textbox is not showing the change.
Here is my code so far...please excuse the commented out code...I haven't gotten it to work correctly:
VB.NET:
Private Sub btnSaveClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveClose.Click
'When Save button is clicked, build SQL Update command, connect to db,
'update row's info in db
Dim updateCmd As String = "UPDATE Locations Set site = @site," _
& "site_refnbr = @siteRefnbr, aac = @aac, telephone_nbr = @phoneNbr" _
& "fax_nbr = @faxNbr, depot_refnbr = @depotRefnbr, freight_refnbr = @freightRefnbr" _
& "dispatch_refnbr = @dispatchRefnbr, Email = @Email"
Dim myCommand As SqlCommand = New SqlCommand(updateCmd, conn)
myCommand.Parameters.Add(New SqlParameter("@site", SqlDbType.VarChar))
myCommand.Parameters.Add(New SqlParameter("@siteRefnbr", SqlDbType.VarChar))
myCommand.Parameters.Add(New SqlParameter("@aac", SqlDbType.VarChar))
myCommand.Parameters.Add(New SqlParameter("@phoneNbr", SqlDbType.VarChar))
myCommand.Parameters.Add(New SqlParameter("@faxNbr", SqlDbType.VarChar))
myCommand.Parameters.Add(New SqlParameter("@depotRefnbr", SqlDbType.VarChar))
myCommand.Parameters.Add(New SqlParameter("@freightRefnbr", SqlDbType.VarChar))
myCommand.Parameters.Add(New SqlParameter("@dispatchRefnbr", SqlDbType.VarChar))
myCommand.Parameters.Add(New SqlParameter("@Email", SqlDbType.VarChar))
'Create array of column names
Dim cols() As String = {"@site", "@siteRefnbr", "@aac", "@phoneNbr", "@faxNbr", _
"@depotRefnbr", "@freightRefnbr", "@dispatchRefnbr", "@Email"}
'Iterate through columns to check for empty values and display message
'box if empty value found and initialize sqlcommand parameter values
'Dim numCols As Integer = Me.Controls.Count
'Dim i As Integer
'Dim colvalue As String
'Dim txtBox As TextBox
''For i = 1 To numCols - 1
' txtBox = Me.Controls.Count(i)
'Next
'BindingContext(dsUpdateDb, "locations").EndCurrentEdit()
'Dim daUpdateDb As New SqlDataAdapter
'Dim dtLocations As New DataTable("Locations")
'Dim cmdUpdateCommandBuilder As New SqlCommandBuilder(daUpdateDb)
''Dim dsUpdateDb As New DataSet
''Dim dtLocations As New DataTable
'Try
' daUpdateDb.Update(dsUpdateDb, "Locations")
'Catch ex As Exception
' MessageBox.Show(ex.Message)
'End Try
'daUpdateDb.Update(dsUpdateDb, "Locations")
'daUpdateDb.Update(dsUpdateDb, dtLocations)
'daUpdateDb.Fill(dtLocations)
'Dim cmdUpdateDb As New SqlCommand
'MessageBox.Show("Do you want to save changes for this location?", "OK", MessageBoxButtons.YesNo)
'Try
' daUpdateDb.Update(dtLocations)
' Console.WriteLine("Location successfully updated")
'Catch ex As Exception
' Console.WriteLine("Call to DataAdapter.Update " & _
' "threw exception:" & vbCrLf & ex.Message)
'End Try
End Sub