pass params + vars to stored proc

Pace

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

Ive never done this before but hey, first time for everything and all that.

VS 2005 - I have a stored procedure on my sql server set to do lots of funky stuff... Only thing is, it needs 3 variables from my app. 2 strings and a date and these need to be passed as parameters.

so...

VB.NET:
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
'Updating...
Me.btnDone.Visible = True
Me.btnUpdate.Visible = False
 
'Pass my stuff and let sql do its thaaang...
 
Look at part 2 of my ado.net tutoria (in sig) ... it goes over parameterized queries. Even though it doesn't use stored procs, passing parameters works the same way.

-tg
 
oooo perfect,

Cheers TG ;-)
 
@ Anyone for reference... and if this helped you, post :cool:

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] cmd [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlClient.SqlCommand[/SIZE]
 
[SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] cmd
.CommandText = [/SIZE][SIZE=2][COLOR=#800000]"yourProcedureName"
[/COLOR][/SIZE][SIZE=2].CommandType = CommandType.StoredProcedure
.Connection = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlConnection([/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Settings.YourConnectionString)
.Parameters.Add([/SIZE][SIZE=2][COLOR=#800000]"@Name"[/COLOR][/SIZE][SIZE=2], SqlDbType.VarChar, 50)
cmd.Parameters.Item([/SIZE][SIZE=2][COLOR=#800000]"@Name"[/COLOR][/SIZE][SIZE=2]).Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtName.Text[/SIZE]
[COLOR=seagreen]'Add more here, dont forget its datatype... int, Date, Char etc...[/COLOR]
[SIZE=2]cmd.Connection.Open()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2]cmd.ExecuteNonQuery()
[/SIZE]
 
Back
Top