Link to home
Start Free TrialLog in
Avatar of craigewens
craigewens

asked on

Using Stored Procedure take values from text boxes and put into SQL Server 2005

Hi,

I am developing a web page form which links into a SQL Server 2005 database.
The database has several stored procedures which get data out and into drop down lists which the web site uses. The stored procedures are simple SELECT statements basically.

I am now at the stage where I've created the whole page with all the controls i require and wish to post the data back into the database.

To simplify the explanation here is the situation...
Web site with a text box and a drop down list.
I have a button which i wish to press and the text from the web controls get pushed into the stored procedure and put into the database.

How do i go about doing this? I'm quite new to .NET and have only really used the wizard type functions on getting data out of my database so please be kind with the explanations.

A probably naive thought on how something like this might be accomplished is shown below (again, please no laughing, i know it's not going to be this easy!)

Sub Button_click()
      Call SQL.StoredProc1(TextBox.Text, DropDownList.SelectedItem)
End Sub


Thank you for any help and sample code you can offer.
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sancler
Sancler

And don't forget to close the connection

        conn.Close()

at the end ;-).  Not for points

Roger



Avatar of craigewens

ASKER

Thanks for the replies... i already have a connection string which i am using in a few places on the web site. Can i utilise the same connection string by referencing it some how instead of writing this?

[quote]
        Dim conn As New SqlConnection("Integrated Security=SSPI;" _
               & "Persist Security Info=False;Initial Catalog=DatabaseName;" _
               & "Data Source=ServerName;")
[/quote]

Also I'm a little confused as to how exactly this line "myCommand.Parameters.Add(TextBox.Text)" knows it should be Parm1 or Parm2?
YZlat,
Almost nothing from you example seemed to work for me, each time i seemed to have double the amount of parameters going into my stored procedure :( It was helpful in assisting me to find a similar solution though... In the end i came across this which seems a much simpler solution.

conn.Parameters.AddWithValue("@ProjectID", ddlProject.SelectedValue)

i added as many parameters as required then finished with conn.ExecuteNonQuery() and then a close().

I'd still really like to know how i reference a connection string i already use for the site though instead of having to hard code it again.
Thanks.
Well i've figured out the ConnectionString question by myself as well now...

Dim cn As New SqlConnection()
cn.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionStringNameHere").ConnectionString
cn.open()