Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Okay, I have written the code to create the parameters for an SP, but how do I run it then loop through the records.

 

I want to do some processing before passing a value back ...

 

I'm using Professional ASP.Net from Wrox and vb.net by Sybex. Both books should be avaoided!!!

 

 

Here is what I have so far:

 

Dim ConStr As String = "provider=SQLOLEDB.1;data source=127.0.0.1;intial catalog=SME;uid=sa;pwd="

 

' Create Instance of Connection and Command Object

Dim myConnection As New SqlConnection(ConStr)

Dim myCommand As New SqlCommand("spInsertUser", myConnection)

Dim objDataReader As SqlDataReader

 

myCommand.CommandType = CommandType.StoredProcedure

 

Dim objParam As SqlParameter

 

objParam = myCommand.Parameters.Add("@name", SqlDbType.NVarChar, 100)

objParam.Direction = ParameterDirection.Input

objParam.Value = name

Posted

If you want to loop through the records returned from that stored procedure, you can use a DataReader to do that.

 

Just add this:

Dim myReader As SqlDataReader = myCommand .ExecuteReader()

Do While myReader.Read()

'**ADD SOME CODE TO READ THE VALUES, IE:

messagebox.show(myReader.GetInt32(0))

Loop

myReader.Close()

 

 

 

Check out this MSDN topic: "SqlDataReader class, samples" for more info.

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...