Home All Groups Group Topic Archive Search About

Code for stored procedures

Author
10 Mar 2006 2:53 AM
Sandy
Hello -

I have been trying to find sample code for inserting into Sql Server 2000. 
I haven't been very successful.  One thing I don't understand from the few
snippets I've seen is how to connect the value in the textbox to the
parameter.

In .Net I would write the following:

<snip>
cmd.Parameters.Add("@TUserID", Session("UserID"))
    cmd.Parameters.Add("@TListType", 4)
    cmd.Parameters.Add("@TFirstName", txtFirstName.Text)
    cmd.Parameters.Add("@TLastName", txtLastName.Text)
<snip>

where it is obvious that the parameter value is coming from the textboxes. 
How and where do I put that into VB6?

I have the following code sample from VB6:

Set oPrm = oCmd.CreateParameter("@fname", adVarChar, adParamInput, 15,
FName)
    oCmd.Parameters.Append oPrm
Set oPrm = oCmd.CreateParameter("@mi", adVarChar, adParamInput, 4, MI)
    oCmd.Parameters.Append oPrm
Set oPrm = oCmd.CreateParameter("@lname", adVarChar, adParamInput, 20,
LName)

How and where would I connect the value from textboxes?  I just plain don't
get it.  I think .Net is much easier, but unfortunately, I can't talk the
powers that be into using it instead of VB6.

Any help will be greatly appreciated!

--
Sandy

Author
10 Mar 2006 9:34 PM
Robert Ellis
Sandy,

> Set oPrm = oCmd.CreateParameter("@fname", adVarChar, adParamInput, 15,
> FName)

In the above line, you are passing whatever value is in the variable FName
as the value of the parameter. It's a simple as that.
So to pass the value that's in a TextBox called TextBox1, you would do:

Set oPrm = oCmd.CreateParameter("@fname", adVarChar, adParamInput, 15,
TextBox1.Text)

OR:

FName = TextBox1.Text
Set oPrm = oCmd.CreateParameter("@fname", adVarChar, adParamInput, 15,
FName)

Note that using CreateParameter, the Value argument is optional. It simply
allows you to specify a value for the Parameter you are creating at the
time, rather than having to specify it later, as in:

Set oPrm = oCmd.CreateParameter("@fname", adVarChar, adParamInput, 15)
oPrm.Value = TextBox1.Text

I don't use .Net, but it seems to me that the .Net syntax is actually very
similar to VB6 (which is not surprising.)

Cheers,

Robert






Show quoteHide quote
"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:1B57FDE6-7EEF-4666-9001-3999FFBFDE59@microsoft.com...
> Hello -
>
> I have been trying to find sample code for inserting into Sql Server 2000.
> I haven't been very successful.  One thing I don't understand from the few
> snippets I've seen is how to connect the value in the textbox to the
> parameter.
>
> In .Net I would write the following:
>
> <snip>
> cmd.Parameters.Add("@TUserID", Session("UserID"))
>    cmd.Parameters.Add("@TListType", 4)
>    cmd.Parameters.Add("@TFirstName", txtFirstName.Text)
>    cmd.Parameters.Add("@TLastName", txtLastName.Text)
> <snip>
>
> where it is obvious that the parameter value is coming from the textboxes.
> How and where do I put that into VB6?
>
> I have the following code sample from VB6:
>
> Set oPrm = oCmd.CreateParameter("@fname", adVarChar, adParamInput, 15,
> FName)
>    oCmd.Parameters.Append oPrm
> Set oPrm = oCmd.CreateParameter("@mi", adVarChar, adParamInput, 4, MI)
>    oCmd.Parameters.Append oPrm
> Set oPrm = oCmd.CreateParameter("@lname", adVarChar, adParamInput, 20,
> LName)
>
> How and where would I connect the value from textboxes?  I just plain
> don't
> get it.  I think .Net is much easier, but unfortunately, I can't talk the
> powers that be into using it instead of VB6.
>
> Any help will be greatly appreciated!
>
> --
> Sandy
Author
11 Mar 2006 4:34 PM
Sandy
Thanks, Robert!
--
Sandy


Show quoteHide quote
"Robert Ellis" wrote:

> Sandy,
>
> > Set oPrm = oCmd.CreateParameter("@fname", adVarChar, adParamInput, 15,
> > FName)
>
> In the above line, you are passing whatever value is in the variable FName
> as the value of the parameter. It's a simple as that.
> So to pass the value that's in a TextBox called TextBox1, you would do:
>
> Set oPrm = oCmd.CreateParameter("@fname", adVarChar, adParamInput, 15,
> TextBox1.Text)
>
> OR:
>
> FName = TextBox1.Text
> Set oPrm = oCmd.CreateParameter("@fname", adVarChar, adParamInput, 15,
> FName)
>
> Note that using CreateParameter, the Value argument is optional. It simply
> allows you to specify a value for the Parameter you are creating at the
> time, rather than having to specify it later, as in:
>
> Set oPrm = oCmd.CreateParameter("@fname", adVarChar, adParamInput, 15)
> oPrm.Value = TextBox1.Text
>
> I don't use .Net, but it seems to me that the .Net syntax is actually very
> similar to VB6 (which is not surprising.)
>
> Cheers,
>
> Robert
>
>
>
>
>
>
> "Sandy" <Sa***@discussions.microsoft.com> wrote in message
> news:1B57FDE6-7EEF-4666-9001-3999FFBFDE59@microsoft.com...
> > Hello -
> >
> > I have been trying to find sample code for inserting into Sql Server 2000.
> > I haven't been very successful.  One thing I don't understand from the few
> > snippets I've seen is how to connect the value in the textbox to the
> > parameter.
> >
> > In .Net I would write the following:
> >
> > <snip>
> > cmd.Parameters.Add("@TUserID", Session("UserID"))
> >    cmd.Parameters.Add("@TListType", 4)
> >    cmd.Parameters.Add("@TFirstName", txtFirstName.Text)
> >    cmd.Parameters.Add("@TLastName", txtLastName.Text)
> > <snip>
> >
> > where it is obvious that the parameter value is coming from the textboxes.
> > How and where do I put that into VB6?
> >
> > I have the following code sample from VB6:
> >
> > Set oPrm = oCmd.CreateParameter("@fname", adVarChar, adParamInput, 15,
> > FName)
> >    oCmd.Parameters.Append oPrm
> > Set oPrm = oCmd.CreateParameter("@mi", adVarChar, adParamInput, 4, MI)
> >    oCmd.Parameters.Append oPrm
> > Set oPrm = oCmd.CreateParameter("@lname", adVarChar, adParamInput, 20,
> > LName)
> >
> > How and where would I connect the value from textboxes?  I just plain
> > don't
> > get it.  I think .Net is much easier, but unfortunately, I can't talk the
> > powers that be into using it instead of VB6.
> >
> > Any help will be greatly appreciated!
> >
> > --
> > Sandy
>
>
>