stored procedures & VB.net (Newbie(ish))

Pace

Well-known member
Joined
Sep 2, 2005
Messages
90
Location
Manchester UK! :)
Programming Experience
1-3
Hi All,

Im looking for some examples on how to pass a value from a control on a form to a sql stored procedure using vb.net...

basically im ok with SQL, im good with VBA and im ok with VB.net... I just want to start tieing the technologies together. I dont need spoon feeding, just some light hearted guidance.

Thanks for your help =)

Pace
 
Passing values to stored procs are easily done using Parameters

For instance:

Dim myconn as new SqlConnection("...connection info...")
Dim myCmd as new SqlCommand("sp_StoredProcedure",myconn)

myCmd.CommandType = CommandType.StoredProcedure
myCmd.Parameters.Add("@ParameterName",parameterType)
...
myCmd.Parameters("@ParameterName").Value = oh lets say TextBox1.Text
...
now you can execute the store procedure ... and so on ...

HTH

Blokz
 
You would need to create an SqlCommand object with the CommandText set to the name of your SP and the CommandType set to StoredProcedure. You would then add SqlParameters to its Parameters collection and assign the desired values to the Value properties of those parameters. Then you would call Fill on an SqlDataAdapter or ExecuteReader, ExecuteScalar or ExecuteNonQuery on the command itself, depending on what the SP does.
 
Back
Top