S
simon
I have cashed dataSet
ds = Cache("userDataSet")
If ds Is Nothing Then
Cache("userDataSet") = createDataSet()
End If
function CreateDataSet
'code for creating dataSet
'SELECT name,surname FROM testUpdate WHERE id=1
end function
Then user change the values in dataSet
and in the end I would like to update this changes to the database.
Function UpdateDatabase
Dim adapterU As New SqlDataAdapter
Dim cmdUpdate As New SqlCommand
Dim myConn As SqlConnection
myConn = New
SqlConnection(ConfigurationSettings.AppSettings("appStrConnection"))
myConn.Open()
cmdUpdate.Connection = myConn
cmdUpdate.CommandType = CommandType.StoredProcedure
Dim name As New SqlParameter("@name", SqlDbType.VarChar, 50)
name.SourceColumn = "name"
cmdUpdate.Parameters.Add(name)
Dim surname As New SqlParameter("@surname", SqlDbType.VarChar, 50)
surname.SourceColumn = "surname"
cmdUpdate.Parameters.Add(surname)
adapterU.UpdateCommand = cmdUpdate
adapterU.Update(ds, "testUpdate")
end function
Stored procedure is:
CREATE PROCEDURE pf_updateUser
@ime varchar(50),
@priimek varchar(50)
AS
UPDATE testUpdate SET
name=@ime,
surname=@priimek
WHERE id=1
This works. I would like to know only if this is the right procedure or is
there some better way for this.
If I have dataSet in session, should I put somehow also adapter in session?
And should I use sqlCommandBuilder somehow?¸
Thank you,
Simon
ds = Cache("userDataSet")
If ds Is Nothing Then
Cache("userDataSet") = createDataSet()
End If
function CreateDataSet
'code for creating dataSet
'SELECT name,surname FROM testUpdate WHERE id=1
end function
Then user change the values in dataSet
and in the end I would like to update this changes to the database.
Function UpdateDatabase
Dim adapterU As New SqlDataAdapter
Dim cmdUpdate As New SqlCommand
Dim myConn As SqlConnection
myConn = New
SqlConnection(ConfigurationSettings.AppSettings("appStrConnection"))
myConn.Open()
cmdUpdate.Connection = myConn
cmdUpdate.CommandType = CommandType.StoredProcedure
Dim name As New SqlParameter("@name", SqlDbType.VarChar, 50)
name.SourceColumn = "name"
cmdUpdate.Parameters.Add(name)
Dim surname As New SqlParameter("@surname", SqlDbType.VarChar, 50)
surname.SourceColumn = "surname"
cmdUpdate.Parameters.Add(surname)
adapterU.UpdateCommand = cmdUpdate
adapterU.Update(ds, "testUpdate")
end function
Stored procedure is:
CREATE PROCEDURE pf_updateUser
@ime varchar(50),
@priimek varchar(50)
AS
UPDATE testUpdate SET
name=@ime,
surname=@priimek
WHERE id=1
This works. I would like to know only if this is the right procedure or is
there some better way for this.
If I have dataSet in session, should I put somehow also adapter in session?
And should I use sqlCommandBuilder somehow?¸
Thank you,
Simon