penfold Posted March 4, 2016 Posted March 4, 2016 I just need clarification on something I'm trying to do. I have created a basic Web Page for entering some details which I have done using text boxes and am inserting into the database using a button with the code using the example: SqlCommand xp = new SqlCommand("Insert into Users(GivenName, Surname) Values(@GivenName, @surname)", vid); xp.Parameters.AddWithValue("@GivenName", TextBox1.Text); xp.Parameters.AddWithValue( @surname", TextBox2.Text); This works, but as the page looks a bit basic I have looked to using form-control which makes the page a little nicer to look at but when I use the corresponding code on the button: SqlCommand xp = new SqlCommand("Insert into Users(GivenName, Surname) Values(@GivenName, @surname)", vid); xp.Parameters.AddWithValue("@GivenName", Request.Form["FirstName"]) Nothing is inserted into the database. As posted in another thread this is something I am just learning so I don't know if this is because I can't do it this way or I'm just doing it wrong. From what I have read the examples seem to point towards using PHP but that is something else I would need to learn and I'm only trying to do some basic user input which a text box would do, but a form-control option looks nicer.
jinnantonnixx Posted March 4, 2016 Posted March 4, 2016 The first thing I'd do is write a debug line to console with the value of a variable that has retrieved Request.Form["FirstName"] See if it contains anything.
penfold Posted March 4, 2016 Author Posted March 4, 2016 Now I thought it was, but I've just tried it again and it isn't showing anything which suggests my code is wrong. The code from my form is currently label for="FirstName">First Name which I am then trying to reference using xp.Parameters.AddWithValue("@GivenName", Request.Form["FirstName"]) To me this now suggests I'm referencing something incorrectly.
penfold Posted March 4, 2016 Author Posted March 4, 2016 Ok, I've just put the same code into a fresh page and it is working. I'm just going to re-create it and tidy the code up again as it doesn't look like there is anything wrong so I assume I must have made some mistake during my testing. Thanks
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now