 |
| VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 6th, 2006, 11:14 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Database does not update, no exception thrown
Im using a dataadapter and dataset in an Employee Class to perform updates. The code runs a select stored procedure to select the employee, and an update SP to update the information. I can run the update SP from server explorer and it will update the database table successfully, but not from the program.
here is the code to send the changes to the DB:
'oEmployee is an instance of Employee
'employeeDA is the DataAdapter
'SELECTED is the Dataset
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Update the Employee in the Database
Try
oEmployee.EmployeeDA.UpdateCommand.Parameters.Add( "@EmployeeID", oEmployee.EmployeeID)
oEmployee.EmployeeDA.UpdateCommand.Parameters.Add( "@ParkingID", oEmployee.ParkingID)
oEmployee.EmployeeDA.UpdateCommand.Parameters.Add( "@PermitNumber", oEmployee.PermitNumber)
oEmployee.EmployeeDA.UpdateCommand.Parameters.Add( "@PermitReturn", oEmployee.PermitReturn)
oEmployee.EmployeeDA.UpdateCommand.Parameters.Add( "@BadgeID", oEmployee.BadgeID)
oEmployee.EmployeeDA.UpdateCommand.Parameters.Add( "@BadgeReturn", oEmployee.BadgeReturn)
oEmployee.EmployeeDA.UpdateCommand.Parameters.Add( "@Credential", oEmployee.Credential)
oEmployee.EmployeeDA.Update(oEmployee.SELECTED)
Catch eInsertException As Exception
MsgBox(eInsertException.ToString, MsgBoxStyle.OKOnly)
Throw eInsertException
Finally
Splatgirl.Close()
End Try
SelectedEmployee.Dispose()
SelectedEmployee = Nothing
Splatgirl.Close()
MsgBox("Employee updated", MsgBoxStyle.OKOnly, "Update Complete")
Me.Refresh()
Me.Close()
End Sub
Here is a listing of the update SP:
CREATE PROCEDURE [dbo].[UpdateEmployeeCS]
(
@EmployeeID uniqueidentifier,
@ParkingID char(10),
@PermitNumber char(10),
@PermitReturn char(10),
@BadgeID char(10),
@BadgeReturn char(10),
@Credential char(10)
)
AS
UPDATE Employees SET
[Permit Number] = @PermitNumber,
[Parking ID] = @ParkingID,
[Permit Return] = @PermitReturn,
[Badge ID] = @BadgeID,
[Badge Return] = @BadgeReturn,
Credential = @Credential
WHERE (EmployeeID = @EmployeeID)
GO
This is the function that sets up the DataAdapter
Public Function GetData(ByVal empLname As String, ByVal empFname As String) As String
Me.SPLATGIRL = New SqlConnection("workstation id=D5WQ1K81;packet size=4096;integrated security=SSPI;data source=SPLATGIRL;persist security info=False;initial catalog=MWPH Employee Processing")
Me.EmployeeDA = New SqlDataAdapter("SelectedEmployee", SPLATGIRL)
Dim dr As DataRow
Dim DAUpdateCmd As New SqlCommand
With DAUpdateCmd
.CommandType = CommandType.StoredProcedure
.CommandText = "UpdateEmployeeCS"
.Parameters.Add("@EmployeeID", EmployeeID)
.Connection = SPLATGIRL
End With
EmployeeDA.UpdateCommand = DAUpdateCmd
With EmployeeDA
.TableMappings.Add("Employees", "SELECTED")
.MissingSchemaAction = MissingSchemaAction.AddWithKey
.SelectCommand.CommandType = CommandType.StoredProcedure
.SelectCommand.Parameters.Add("@LastName", empLname)
.SelectCommand.Parameters.Add("@FirstName", empFname)
.FillSchema(SELECTED, SchemaType.Source)
.Fill(SELECTED) ' null dataset
End With
End Function
SO if anyone can help me figure out why this will not update the table , I would really appreciate it.
|
|

November 6th, 2006, 11:30 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
hi there.. do you recive any error?? or nothings happends???
HTH
Gonzalo
|
|

November 6th, 2006, 12:03 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
no, no error, no exception, the code all runs , but the table does not get updated
|
|

November 6th, 2006, 01:22 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
mm.. are you sure that you are passing the rigth employeeID.. maybe that ID is wrong and that's why you are not updating anything...
can you trace the data you are giving to the command???
HTH
Gonzalo
|
|

November 6th, 2006, 02:50 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am sure that the Employee ID is correct, and all of the data is passed correctly to the procedure.
|
|

November 24th, 2006, 03:28 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If you have added the database to the solution, then every time you attempt to debug the program, it will copy the original database to the solution in the debug folder.
Try this:
run the program in debug, update your information, then go to the debug folder in projects folder, open the database in the external application (access, sql server, oracle, etc.) This will show you if it is actually updating the information
Hope this helps.
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.
Albert Einstein
US (German-born) physicist (1879 - 1955)
|
|
 |