Inserting data from web form not working?

H

hfk0

Hi,

I'm using the following parameters in my web form:

cmdTest.Parameters.Add(New SqlParameter("@FirstN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@LastN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@Org",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@Addr1",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@City",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@Email",
SqlDbType.NVarChar, 50))
cmdTest.Parameters("@FirstN").Value = "FirstN"
cmdTest.Parameters("@LastN").Value = "LastN"
cmdTest.Parameters("@Org").Value = "Org"
cmdTest.Parameters("@Addr1").Value = "Addr1"
cmdTest.Parameters("@City").Value = "City"
cmdTest.Parameters("@Email").Value = "Email"

When I submit the form, somehow it didn't insert the info. I'm only
seeing "FirstN" "LastN" "Org" "Addr1" "City" and "Email" in the
corresponding columns in the database.

Could anyone help me with this? Am I using the right code?

Thanks,
hfk0
 
G

Guest

hfk0,
Yes, because that is precisely what you are inserting - the literal string
values
"FirstN", "LastN" etc.
if you have Form Fields with these names, you probably want to use
this.FirstN.Text as the parameter value instead of the literal string
"FirstN".
What you get out is what you put in.
Hope that helps.
Peter
 
H

hfk0

Hi Peter,

Thanks for clearing things up. I replaced the literal string value with
FirstN.Text and it works like a charm.

Is there a difference between using this.FirstN.Text and FirstN.Text?

Also, I tried to add the following:

cmdTest.Parameters.Add(New SqlParameter("@State", SqlDbType.NChar, 2))
cmdTest.Parameters("@State").Value = State.SelectedItem.Value

and

cmdTest.Parameters.Add(New SqlParameter("@Phone", SqlDbType.VarChar,
10))
cmdTest.Parameters("@Phone").Value = Phone.Text

The state and phone values didn't get inserted into the database (I
tried using "numeric" instead of "varchar" but didn't help either). Any
clues?


Thanks again.

hfk0
 
G

Guest

"this" in C# (or "Me" in VB.NET) simply provides you with a convenient
reference to the current class that you are in. Type a dot (".") after that
and Intellisense kicks in for you.
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top