Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whats wrong with this Insert Into Statement?? 1

Status
Not open for further replies.

onedizzydevil

Programmer
Mar 24, 2001
103
US
I can not figure out whats "wrong" with this statement in ASP.NET, any ideas. Thanks

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

Dim sql As New SqlConnection(ConfigurationSettings.AppSettings("sql"))

sql.Open()

Dim com As New SqlCommand("INSERT INTO prod_engine (emailaddress, password, nameFirst, nameLast, birthday, sex, removed) VALUES ('" & txtEmailAddress.Text & "', '" & txtPassword.Text & "', '" & txtNameFirst.Text & "', '" & txtNameLast.Text & "', '" & txtBirthday.Text & "', '" & rdoSex.SelectedItem & "', 0)", sql)

com.ExecuteNonQuery()

sql.Close()
End Sub


ASP.NET Visual/Build Error Message:
Operator '&' is not defined for types 'String' and 'Sysemt.Web.UI.WebControls.ListItem'. Wayne Sellars

"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
 
Hey Wayne,

Do any of the values you're passing contain ' or " in them?

Jack
 
No, technically there is no value yet. It is not a runtime error or problem yet, it is a build error. It says, Operator '&' is not defined for types 'String' and 'Sysemt.Web.UI.WebControls.ListItem'. Wayne Sellars

"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
 
Just a thought: that rdoSex.SelectedItem, doesn't it represent an integer, not a string? I thought it returns the index, not the actual value. Try taking the single quotes away from it and see if it still has a problem.

Jack
 
You are correct is was an int; however, it did fix problem. The problem is just two tick marks shorter than it was.

This is very weird all of the examples that I see on the internet use the exact sytax. Is there any imports that I need? Wayne Sellars

"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
 
Are you writing this in visual studio, or just in a text editor?

Can you email me the source and I can take a look at it (fresh set of eyes over the whole picture sometimes helps).

jfrost10@yahoo.com

Also, if it is a text editor you're using, check and make sure any code above this that uses " or ' have beginning and ending quotes. if one goes wanky earlier on, it'll screw up the whole page.

jack
 
You will be receiving it shortly.

Thank you Wayne Sellars

"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
 
Got it!

What you have to do is add .Value to the end of your rdoSex.SelectedItem

Which makes sense, because you can't just send the item itself, you just want to send the value. If you add it so it'll look like this:

" & rdoSex.SelectedItem.Value & ", 0)", sql)

that should take the blue line away (did in my project) and fix the problem

:)

Jack
 
Now I have a question for you Wayne: how did you create those ascx control files in your project? I havn't ventured into custom controls yet, and the only web controls I can find to create in vs.net all have a .vb extension to them. Whats the trick?

Jack
 
Uh, I think I figured it out, but it seems kinda clunky:
So to make an ascx page, i have to make a web form (aspx) page, then just change the extension? And if I want to add it to a library file, I have to create a dll seperately and just add the file to it instead of creating it within?!

Crazy stuff!

Jack
 
Nope! If you rename a Web Form to a web control you will have problems, or at least I did. If you do a right click in the Solutions Explorer either on a the distination folder or the project name, and select Add>Add Web User Control. This will add a new .ascx file for you, the stuff that I have read on this is that is the "new, more powerful, server side include" which is cool it does allow for reuseability and the fact that you can add them dynamically as well as staticly is really awesome because you can now move an entire control not matter what is to a different cell.

But one down fall that I read about this is that is *has* to be used inside an existing form. Well I have always liked to have my log information on every public that person can go to and let say a person is not logged and you use validator on for login elements, know lets say that joe user cruses over to the comments page know the comments page has a form which is postback which know contains the login elements. Now when the user goes to submit a comment the valiadtors fire for the login form also because they on on that form.

Ideally, it would be better to have each item in a separate for that does not mess with each other, but as of right now it does not seem to work that way. The only solution that I can think of is to manually fire the validators that you are concerned with based off of the button you clicked. I have not tried that yet but it is on my todo list. Wayne Sellars

"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
 
Yeah, its a neat concept (heh, and one that isn't documented very well).
;)

Keep me posted on what you find out with the web controls, and if I come accross anything ground-breaking I'll letyou know.

Jack

p.s. did that .value code fix your insert statement?
 
Yes, the .value did work. I try that once before but the blue line did not go away. I made the change this time and save it, when and got something to drink and came back the blue line was gone away.

I guess I would have been able to fix it if I was not in such a hurry. The software seems to be quick on tell you make a mistake but slower on the rechecks, I guess. Don't total know whats was up with that.

Will keep you update on the web control, they do seem to be off to good start, but like just about everything right now documentation is lacking. However, that should be fixed pretty soon on once everyone gets started using the Gold Code.

Thanks for you help!

Wayne Sellars

"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
 
Hey Wayne, I'm playing around with a template web control (kinda like the one you had with your source code). Question: how were you able to set the runat property of the individual table cell to runat? I'm trying to add a control to a cell, but I keep getting an "object not referenced" error, even though my code is pretty much identical to yours. I thought maybe if that runat property wasn't set to server it wouldn't fly, but any thoughts on it?

thanks,
Jack
 
Heh, nevermind Wayne, figured it out (right click and select "run as server control", right?)
;)

Jack
 
Also, you can play with cell visibility and row visiblity by adding this line to your Protected WithEvents:

Protected WithEvents cellrowname As System.Web.UI.HTMLControls.[HtmlTableRow / HtmlTableCell]

Then in your event or pageload you can

cellrowname.visible = [True / False]

Keep in mind that red line shows up in the HTML view if you code a default visiblity &quot; <tr ..... visible=&quot;false&quot; ...</tr>&quot; and it will flag you in the in Task Lisk on your build, but it will work. Wayne Sellars

&quot;Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top