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.Te xt, DropDownList.SelectedItem)
End Sub
Thank you for any help and sample code you can offer.
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.Te
End Sub
Thank you for any help and sample code you can offer.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.Te xt)" knows it should be Parm1 or Parm2?
[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(
ASKER
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.AddWithVal ue("@Proje ctID", 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.
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.AddWithVal
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.
ASKER
Well i've figured out the ConnectionString question by myself as well now...
Dim cn As New SqlConnection()
cn.ConnectionString = ConfigurationManager.Conne ctionStrin gs("Connec tionString NameHere") .Connectio nString
cn.open()
Dim cn As New SqlConnection()
cn.ConnectionString = ConfigurationManager.Conne
cn.open()
conn.Close()
at the end ;-). Not for points
Roger