Click to See Complete Forum and Search --> : SqlHelper.UpdateDataset Help


SuPerNoVi
03-15-2007, 10:39 AM
Okay so here is my code thus far on the click of the update button...

Public Sub Update_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Update.Click

Dim command_builder As SqlCommandBuilder
Dim Connection As SqlConnection = New SqlConnection(C.ConnString)
Connection.Open()

Dim Command As SqlCommand = New SqlCommand()
Command.Connection = Connection
Command.CommandText = "Web_A2Z_GetValuesFromBasket"
Command.CommandType = CommandType.StoredProcedure

Dim Parameter As SqlParameter = New SqlParameter("@SearchString", "eid:t.jarram@gmail.com")
Parameter.Direction = ParameterDirection.Input
Parameter.DbType = DbType.String
Command.Parameters.Add(Parameter)

Dim insertCommand As SqlCommand = SqlHelper.CreateCommand(Connection, "Customer_Insert", "CustomerId", "CustomerName")
Dim updateCommand As SqlCommand = SqlHelper.CreateCommand(Connection, "Customer_Update", "CustomerId", "CustomerName", "TimeStamp")
Dim deleteCommand As SqlCommand = SqlHelper.CreateCommand(Connection, "Customer_Delete", "CustomerId")

'Dim Adapter As SqlDataAdapter = New SqlDataAdapter(Command)
Dim Adapter As New SqlDataAdapter(Command)
command_builder = New SqlCommandBuilder(Adapter)

Adapter.Update(DataSet)

End Sub

The bit in particular I am struggling with is the commands...

Dim insertCommand As SqlCommand = SqlHelper.CreateCommand(Connection, "Customer_Insert", "CustomerId", "CustomerName")
Dim updateCommand As SqlCommand = SqlHelper.CreateCommand(Connection, "Customer_Update", "CustomerId", "CustomerName", "TimeStamp")
Dim deleteCommand As SqlCommand = SqlHelper.CreateCommand(Connection, "Customer_Delete", "CustomerId")

I am trying to update the dataset and then pass it to the database at the end but what am I doing wrong. Do I have to create a stored procedure for each instance IE update or delete record?

Any help greatly appreciated :)

PeOfEo
03-15-2007, 11:00 AM
I have never really used stored procedures, I just generally create a data access class with select, update, insert, and delete methods that I can pass the data set to, or a hash table, etc. But I am pretty sure you have all of your stored procedures pretty well covered. I don't see why you should need one for every instance. What I am confused about is why you are using the sqlcommandbuilder, why don't you just pass the updatecommand right into the adapter and execute it if the command is already built?

SuPerNoVi
03-15-2007, 11:54 AM
To be honest I am not entirely sure. I did some research on the net and found that as should work. I am just trying to get the thing to work, after that I can find out what code is relevant or not.

How would you go about doing it? any resources you can point me to?

PeOfEo
03-15-2007, 01:45 PM
Well, what exactly are you doing? Big picture, Sounds like you have some sort of data grid that you are populating and then the user is able to modify the entries in it, so you are pulling in a data set, putting it in the grid, then the user modifies the grid, thus updating the data set, and then at the end you wanna put that data set back into the table?

You seem to be on the right tracking using a stored procedure. Performance wise, it is probably more efficient to do the processing on the DB server. But, unfortunately TSQL isn't my forte. Just for the sake of having it up, would you mind posting one of the procedures so I can see what's going on with it? I have never had to actually pull in a data set, modify that, and then put that back into the db so I kinda wanna see how you're going that. Right now, like I said, I am using a data access class (really because that is what my co-workers and I are comfortable with, its easy to just keep that in source safe and open it at will, and it's in a familiar format), then I am just updating the entries that changed (I am using AJAX so when a drop down list or something in my table changes that posts back to the server with an ID, then it runs a single update command).

SuPerNoVi
03-16-2007, 05:01 AM
Big picture, Sounds like you have some sort of data grid that you are populating and then the user is able to modify the entries in it, so you are pulling in a data set, putting it in the grid, then the user modifies the grid, thus updating the data set, and then at the end you wanna put that data set back into the table?
Bang on right. I am just having trouble getting it to the dataset and then putting it into the database.