hhmmmmmm....t-SQL? I'm not familiar with that term. This is an MSSQL server.
Main Topics
Browse All TopicsI have three controls on my page. Two textboxes (txtusername and txtpassword) and a submit button (btnAdd)
When I click my button it runs the sub to add the user to the database.
I am not getting any errors but my SQL table is not being updated. The screen just posts back like nothing happened.
Any ideas guys?
Attached is the code in my subroutine minus my connection info...
Thanks in advance!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Transact SQL is the flavour of sql used by sql server. If I were writing an insert query within SQL Server it would look like:
INSERT INTO userid (username, password, marketcenter)
VALUES ('value1', 'value2', 'value3')
assuming those fields are all string datatypes (char or varchar).
As the field values are surrounded by single quotes, sql server knows to interpret them as literals rather than column names.
If I were contructing a SQL statement to run then it would look a bit like this:
Declare @SQL_Statement varchar(500)
Declare @username varchar(50)
Declare @password varchar(50)
Declare @marketcenter varchar(50)
set @SQL_statement =
'INSERT INTO userid (username, password, marketcenter)
VALUES (''' + @username + ''','' '
+ @password + ''', '''
+ @MarketCenter + ''')'
exec @sql_statement
In that code I have bunches of single quotes. If I set the following values for username, password, etc,
set @username = 'Tom'
Set @password = 'secret'
set @marketcenter = 'middle'
the the statement that would be executed is:
INSERT INTO userid (username, password, marketcenter) VALUES ('Tom',' secret', 'middle')
So...
Extrapolating that back to your .Net code, I simply added single quotes at appropriate spots so that the command you end up running looks similar to the example above.
Hope that makes sense.
Awesome thanks for that explanation. However, I am still getting the same response. No error but no add. Let me pose this question to you if you don't mind. My table actually has 5 columns. On my INSERT statement I am inserting 3 as you can see. The other two columns are the key (which I have told SQL server to generate automatically as an integer) and also an admin column which I told to set default as 0. Do I need to include these columns into my INSERT statement somehow? I assumed that since they are set to generate automatically and also to be set as a default that I would just have to insert the 3 columns I am trying here. Does that make sense?
Upping points...
You don't need to specify all column names as long as the other columns have:
either default or generated values (eg an identity column)
or allow null values.
I don't do a lot .Net programming but I can think of a couple of ways you can try to work out what is going on:
Generate the command are going to execute and display it. Then copy and paste to a SQL Server management studio window and execute it there to see what happens. Make sure you are using the same credentials as are used in your app.
Eg
dim the_command as string
the_command = "INSERT INTO userid (username, password, marketcenter) VALUES ('" & txtUsername.text & "',' " & txtPassword.text & "', '" & strMarketCenter & "')"
response.write the_command (or run within debugger and set a watch on the_command)
Sorry if my syntax is out of date.
I understand that sqlcommand.executenonquery
Business Accounts
Answer for Membership
by: pettmansPosted on 2009-11-03 at 19:54:52ID: 25736261
You might need to include some single quotes if this is T-SQL syntax
Dim cmd As New SqlCommand("INSERT INTO userid (username, password, marketcenter) VALUES ('" & txtUsername.text & "',' " & txtPassword.text & "', '" & strMarketCenter & "')", con)