passing parameter to VS created dataset...

lidds

Well-known member
Joined
Oct 19, 2004
Messages
122
Programming Experience
Beginner
I have created a datasource using VS and linked it to a stored procedure in my database. This has intern created a dataset, bindingsource and tableadapter the problem that I have is that my stored procedure that the datasource is using is expecting a parameter @projName. What I need to know is how I can pass the parameter name into the dataset using VB.net code??

Thanks in advance

Simon
 
here's a sample of how to use parameter;s


VB.NET:
Public Function getBookCount(ByVal AuthorID As String) As Integer
Return 0
End Function 'getBookCount

In the body of the method, create an instance of the SqlConnection class and pass in connection information with the instantiation of the SqlConnection object.
Dim cnPubs As New SqlConnection("server=localhost;integrated security=true;" + "database=pubs")

Next, create a SqlCommand object and set the appropriate properties needed to execute the up_AuthorBookCount stored procedure created earlier.

Dim cmdAuthors As New SqlCommand("up_AuthorBookCount", cnPubs)cmdAuthors.CommandType = CommandType.StoredProcedure

Using the Add method of the SqlCommand's Parameter collection add an input parameter that takes the AuthorId value passed in by the caller. Also add an output parameter that will store the value passed back by the stored procedure. The names and data types of the parameters must mach those defined in the stored procedure.

cmdAuthors.Parameters.Add("@au_id", SqlDbType.NVarChar, 11)cmdAuthors.Parameters("@au_id").Value = AuthorID '
cmdAuthors.Parameters.Add("@Count", SqlDbType.Int)
cmdAuthors.Parameters("@Count").Direction = ParameterDirection.Output 
'method of the command object

Once the stored procedure is executed, the value of the output parameter is held in a local variable, which is in turn passed back to the client. Don't forget to close the connection after executing the stored procedure.

cnPubs.Open()
Dim iCount As Integer
cmdAuthors.ExecuteNonQuery()
iCount = CInt(cmdAuthors.Parameters("@Count").Value)
cnPubs.Close()
Return iCount
end function
 
Nooo, vinnie, you completely missed the point of the post. He's using typed datasets and has moved on into the future, ahead of your need to use the old methods of data access because youre on 1.1 (nudge nudge, make the jump up to 2.0 at least.. its worht it)

lidds:
yes, your use of the stored procedure has caused whichever TableAdapter you added it to, to now support an extra method. Suppose you added your stored procedure to the ProjectsTableAdapter, and chose to call it GetHoursWorkedOnProject

you would now do:
VB.NET:
Dim hrsWrkd as Integer = Me.projectsTableAdapterInstance.GetHoursWorkedOnProject("PROJ124")

Me. refers to the form
projectsTableAdapterInstance refers to the instance of the ProjectsTableAdapter on the form
GetHoursWorkedOnProject refers to the method(function) exposed on the table adapter
"PROJ124" is the string of the project ID that you want the hours for
 

Latest posts

Back
Top