asked on
Imports System.Data.SqlClient
Public Class dataUserAccess
Private cnKPI As SqlConnection
Private daUsers As SqlDataAdapter
Private cmdSelectUsersInfo As SqlCommand
Private cmdUpdateUsersInfo As SqlCommand
Private cmdInsertUsersInfo As SqlCommand
Private cmdDeleteUsersInfo As SqlCommand
Private dsUsers As DataSet
Public Sub New()
'Connection
cnKPI = New SqlConnection("")
'select command
cmdSelectUsersInfo = New SqlCommand
cmdSelectUsersInfo.Connection = cnKPI
cmdSelectUsersInfo.CommandType = CommandType.StoredProcedure
cmdSelectUsersInfo.CommandText = "proc_UserAccess_All"
'update command
cmdUpdateUsersInfo = New SqlCommand
cmdUpdateUsersInfo.Connection = cnKPI
cmdUpdateUsersInfo.CommandType = CommandType.StoredProcedure
cmdUpdateUsersInfo.CommandText = "proc_UserAccess_Update"
cmdUpdateUsersInfo.Parameters.Add("@UserID", SqlDbType.VarChar, 50, "UserID")
cmdUpdateUsersInfo.Parameters.Add("@Username", SqlDbType.VarChar, 50, "Username")
cmdUpdateUsersInfo.Parameters.Add("@InvoiceAccuracy", SqlDbType.Bit, 1, "InvoiceAccuracy")
cmdUpdateUsersInfo.Parameters.Add("@EmployeeAccidentRate", SqlDbType.Bit, 1, "EmployeeAccidentRate")
cmdUpdateUsersInfo.Parameters.Add("@Settings", SqlDbType.Bit, 1, "Settings")
cmdUpdateUsersInfo.Parameters.Add("@Users", SqlDbType.Bit, 1, "Users")
cmdUpdateUsersInfo.Parameters.Add("@Active", SqlDbType.Bit, 1, "Active")
cmdUpdateUsersInfo.Parameters.Add("@UniqueKey", SqlDbType.Int, 1, "UniqueKey")
'insert command
cmdInsertUsersInfo = New SqlCommand
cmdInsertUsersInfo.Connection = cnKPI
cmdInsertUsersInfo.CommandType = CommandType.StoredProcedure
cmdInsertUsersInfo.CommandText = "proc_UserAccess_Insert"
cmdInsertUsersInfo.Parameters.Add("@UserID", SqlDbType.VarChar, 50, "UserID")
cmdInsertUsersInfo.Parameters.Add("@Username", SqlDbType.VarChar, 50, "Username")
cmdInsertUsersInfo.Parameters.Add("@InvoiceAccuracy", SqlDbType.Bit, 1, "InvoiceAccuracy")
cmdInsertUsersInfo.Parameters.Add("@EmployeeAccidentRate", SqlDbType.Bit, 1, "EmployeeAccidentRate")
cmdInsertUsersInfo.Parameters.Add("@Settings", SqlDbType.Bit, 1, "Settings")
cmdInsertUsersInfo.Parameters.Add("@Users", SqlDbType.Bit, 1, "Users")
cmdInsertUsersInfo.Parameters.Add("@Active", SqlDbType.Bit, 1, "Active")
cmdInsertUsersInfo.Parameters.Add("@CreateDate", SqlDbType.DateTime, 1, "CreateDate")
cmdInsertUsersInfo.Parameters.Add("@CreatedBy", SqlDbType.VarChar, 50, "CreatedBy")
'Delete command
cmdDeleteUsersInfo = New SqlCommand
cmdDeleteUsersInfo.Connection = cnKPI
cmdDeleteUsersInfo.CommandType = CommandType.StoredProcedure
cmdDeleteUsersInfo.CommandText = "proc_UserAccess_Delete"
cmdDeleteUsersInfo.Parameters.Add("@UniqueKey", SqlDbType.Int, 1, "UniqueKey")
'DataApapter
daUsers = New SqlDataAdapter
daUsers.SelectCommand = cmdSelectUsersInfo
daUsers.UpdateCommand = cmdUpdateUsersInfo
daUsers.InsertCommand = cmdInsertUsersInfo
daUsers.DeleteCommand = cmdDeleteUsersInfo
'Dataset
dsUsers = New DataSet()
End Sub
Public Function GetUsersInfo() As DataSet
daUsers.Fill(dsUsers)
Return (dsUsers)
End Function
Public Sub UpdateUsersInfo(ByVal dsChanges As DataSet)
daUsers.Update(dsChanges)
End Sub
End Class
ASKER
ASKER
ASKER
ASKER
ASKER
PROCEDURE spAjoutPhoto ( @Titre nvarchar(75), @NoSujet int, …
@NoPhoto int OUT)
INSERT INTO tbPhotos( Titre , NoSujet… )
VALUES (@Titre , @NoSujet… )
SET @NoPhoto = @@IDENTITY
Here is the Command object used to call it. The lines that set the connection and the procedure are removed to concentrate on what is important, the Direction in the last line:
Dim comPhotos As New SqlClient.SqlCommand()
With comPhotos
.Parameters.AddWithValue("@Titre", strTitre)
.Parameters.AddWithValue("@NoSujet", cboSujet)
…
.Parameters.Add(New SqlClient.SqlParameter("@NoPhoto",SqlDbType.Int))
.Parameters("@NoPhoto").Direction = ParameterDirection.Output
End With
And after the procedure is executed, here is how I retrieve the new ID:Dim no As Integer
no = comPhotos.Parameters("@NoPhoto").Value
ASKER
Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.
TRUSTED BY
what you will need to do is add to your SQL and create Race conditions
if you are unfamiliar with what a race condition is this should explain it clearly
http://www.celticwolf.com/blog/2010/04/27/what-is-a-race-condition/