Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

So are you saying that I could have referred to a dataset in the code below (instead of the way I did it)

 

---

       Dim cmd As New SqlCommand
       Dim conn As New SqlConnection(hpdmdbConnString)
       Dim counter As Integer

       cmd.Connection = conn

       cmd.CommandType = CommandType.StoredProcedure
       cmd.CommandText = "usp_rolelookup"
       cmd.Parameters.Add("@username", currentuser)

       ' Open the connection
       conn.Open()
       ' And run the stored procedure command we have set up in CMD
       objreader = cmd.ExecuteReader
       ' Did we get any rows back? If so then loop through our objreader and add the single column of data
       ' to the arraylist.
       counter = 0
       If objreader.HasRows Then
           While (objreader.Read())
               counter = counter + 1
               getUserRoles.Add(objreader.GetString(0))
           End While
       End If

Posted

               Dim MyAdapter As New SqlClient.SqlDataAdapter("usp_rolelookup", conn)
               Dim MyDataset As New DataSet
	' set the command type
               MyAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
	' add the parameters
               MyAdapter.SelectCommand.Parameters.Add("@username", currentuser)
	' Use the dataadapter to fill the dataset
               MyAdapter.Fill(MyDataset)
               If MyDataset.Tables.Count > 0 Then
		' do somthing with the dataset
               End If

 

Nice and easy use the dataadapters fill command to fill a disconnected dataset with the stored procedures results

 

Regards

 

Andy

Code today gone tomorrow!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...