Print Page | Close Window

& Problem

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=7045
Printed Date: 28 March 2026 at 4:08am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: & Problem
Posted By: IrishNewbie
Subject: & Problem
Date Posted: 06 November 2003 at 9:37am

This is similar to the problem further down the page but im still stumped.

The error is: BC30452: Operator '&' is not defined for types 'String' and 'System.Web.UI.WebControls.TextBox'

my SQL statement is as follows.

aQuery = "Insert Into Students(StudentID, EmailName) VALUES ('"& StudID &"', '"& Email &"')"

Im trying to take the StudID and Email from two textboxes. Is there a couple of lines to take the data from the textboxes and convert it or where am i going wrong??
Appreciate and suggestions.

Thanks




Replies:
Posted By: Mart
Date Posted: 06 November 2003 at 9:39am

('"& StudID &"', '"& Email &"')" i am assuming StudID and Email are text boxes. You have to use

('"& StudID.text &"', '"& Email.text &"')"

Mart.



Posted By: IrishNewbie
Date Posted: 06 November 2003 at 9:49am

Thanks very much marty,

Was having awful trouble with what is a simple error! Only started ASP.Net few weeks ago.

 



Posted By: Mart
Date Posted: 06 November 2003 at 10:01am
Its alright i know how you feel, i only started a month or so ago...


Posted By: IrishNewbie
Date Posted: 06 November 2003 at 10:16am

Marty another question, say i have 5 fields on my form, Student Id, First Name, Last Name, Password, Email.  In my table they are not in that order.  Does that make a difference for taking them in?? I can get it to work for just the StudID and Email but when i try adding the next few i get an error that theres wrong SQL syntax.

 

Bit messy:

Insert Into Students(StudentID, FirstName, LastName, BirthDate, Password, EmailName)

VALUES ('"& StudID.Text &"', '"& F_Name.Text &"', '"& L_Name.Text &"', '"& D_O_B.Text &"', '"& Password1.Text &"', '"& Email.Text &"')"



Posted By: Mart
Date Posted: 06 November 2003 at 10:30am

Im not certain what you mean, but if there are StudentID FirstName LastName BirthDate Password and EmailName columns then the SQL you posted will work.

For more info on INSERT INTO http://www.w3schools.com/sql/sql_insert.asp - http://www.w3schools.com/sql/sql_insert.asp

Mart.



Posted By: IrishNewbie
Date Posted: 06 November 2003 at 10:31am

Disregard the last question marty.  Realised it doesnt.

The problem is with the password entry. at the moment i have 2 password fields, password1, password2.  I intend to do a comaprison to ensure they match but at the moment if i only enter data into the first box it gives me an error, when i leave password out of the sql statement it enters the rest perfect. 

Also, sometimes i have to click the create account button twice for the record to go in. the second time i press it, it tells me that theres already a record in there matching.

 



Posted By: Mart
Date Posted: 06 November 2003 at 10:37am

You dont need password fields in your db you can just use

If not password1.Text = Password2.Text Then

'if the passwords are wrong

End If

And if you click buttons twice your browser will request the page again thus the insert into query to your database so there will be two lots of the record.



Posted By: IrishNewbie
Date Posted: 07 November 2003 at 6:30am

Marty, the problem with the create account button is that sometimes when its pressed once the record isnt created and i have to click it again for it to be put in.

Do i not need a password field in the DB for when the user returns to log into his account????



Posted By: Diep-Vriezer
Date Posted: 07 November 2003 at 9:00am
You could create a routine (sub) wich will add the data, and afterwards validates that the data is there. If not, it will add it again, and so on.

-------------
Gone..


Posted By: IrishNewbie
Date Posted: 07 November 2003 at 9:47am
is that for entering the password??? is there a reason that the DB wont accept the password when its basically a string like the rest of the fields???  Its frustrating cos thats the only field it wont enter into the DB.


Posted By: Diep-Vriezer
Date Posted: 09 November 2003 at 7:18am

Wait. That routine is used to be sure the data gets into the database, because you have to push the button twice. Not really efficient, but it works.



-------------
Gone..


Posted By: IrishNewbie
Date Posted: 09 November 2003 at 9:16am

Can you think of any reason why i am having trouble inserting the password data only?? its the only field it wont take.

 



Posted By: Diep-Vriezer
Date Posted: 09 November 2003 at 10:45am

Post you code. It should look like this:

If txtPwd1.Text = txtPwd2.Text Then

'The database routine

Else

'The error msg.

End If

By the way, VB.NET has validators, which do this kind of validation BEFORE the data goes into the database. That might be a solution.



-------------
Gone..


Posted By: IrishNewbie
Date Posted: 09 November 2003 at 11:58am
I think i figured out whats wrong, is Password a reserved word in Access?? I changed the column name from Password to Pword and its working ok now.


Posted By: Diep-Vriezer
Date Posted: 09 November 2003 at 12:57pm
 Yes password is a reserved word.. Just like FROM, WHERE, INSERT, DELETE etc.

-------------
Gone..


Posted By: IrishNewbie
Date Posted: 09 November 2003 at 5:00pm
rookie mistake!!! still struggling to pick up this asp.net!!!!!!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net