ASP.NET easy newby question

G

Guest

I am trying to store a string into a string variable via the following code
however am receiving an error and cant figure out what i am doing wrong. Any
feedback is greatly appreciated.


Line 49: Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button1.Click
Line 50:
Line 51: Dim strSQL As String = "INSERT INTO Investors
(FNAME,LNAME,EMAIL,ADDRESS1,ADDRESS2," & _
Line 52:
"CITY,STATE,ZIP,PNUMBER,ANUMBER,ATYPE,BESTTIME,INT_PRICERANGE1," & _
Line 53:
"INT_PRICERANGE2,INT_LOCATION,INT_WHEN,PRODUCTS_PURCHASED) VALUES ('" & _
 
T

Tor Bådshaug

Well, if your code terminates like this (line 53) it is no wonder you get an
error. By using "& _" the compiler will expect another line of code. Your
code suggests there actually exists a line 54, but somehow it fell out? Post
your line 54 onwards and I will try to help.

Tor Bådshaug
tor.badshaug [//at\\] bekk.no.
 
G

Guest

Here is all of the code:

Dim strSQL As String = "INSERT INTO Investors
(FNAME,LNAME,EMAIL,ADDRESS1,ADDRESS2," & _

"CITY,STATE,ZIP,PNUMBER,ANUMBER,ATYPE,BESTTIME,INT_PRICERANGE1," & _

"INT_PRICERANGE2,INT_LOCATION,INT_WHEN,PRODUCTS_PURCHASED) VALUES ('" & _
FNAME.Text & "','" & _
LNAME.Text & "','" & _
EMAIL.Text & "','" & _
ADDRESS.Text & "','" & _
ADDRESS1.Text & "','" & _
CITY.Text & "','" & _
dState.SelectedItem.Text & "','" & _
ZIP.Text & "','" & _
PNUMBER.Text & "','" & _
ANUMBER.Text & "','" & _
AType.SelectedItem.Text & "','" & _
BESTTIME.SelectedItem.Text & "','" & _
INT_PRICERANGE1.Text & "," & _
INT_PRICERANGE2.Text & "," & _
INT_LOCATION.Text & "','" & _
INT_WHEN.Text & "','" & _
PRODUCTS.Text & "')"



Tor BÃ¥dshaug said:
Well, if your code terminates like this (line 53) it is no wonder you get an
error. By using "& _" the compiler will expect another line of code. Your
code suggests there actually exists a line 54, but somehow it fell out? Post
your line 54 onwards and I will try to help.

Tor BÃ¥dshaug
tor.badshaug [//at\\] bekk.no.
Line 53:
"INT_PRICERANGE2,INT_LOCATION,INT_WHEN,PRODUCTS_PURCHASED) VALUES ('" & _
 
T

Tor Bådshaug

And what is the error message you get? Compile error or runtime error?

Tor Bådshaug
tor.badshaug [//at\\] bekk.no.

....
 
G

Guest

The error says Server Error in '/WebApp' Application

Object reference not set to an instance of an object
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object

It's like it has an issue with setting the string to the variable.... i'm
stumped!

Ryan Smith said:
Here is all of the code:

Dim strSQL As String = "INSERT INTO Investors
(FNAME,LNAME,EMAIL,ADDRESS1,ADDRESS2," & _

"CITY,STATE,ZIP,PNUMBER,ANUMBER,ATYPE,BESTTIME,INT_PRICERANGE1," & _

"INT_PRICERANGE2,INT_LOCATION,INT_WHEN,PRODUCTS_PURCHASED) VALUES ('" & _
FNAME.Text & "','" & _
LNAME.Text & "','" & _
EMAIL.Text & "','" & _
ADDRESS.Text & "','" & _
ADDRESS1.Text & "','" & _
CITY.Text & "','" & _
dState.SelectedItem.Text & "','" & _
ZIP.Text & "','" & _
PNUMBER.Text & "','" & _
ANUMBER.Text & "','" & _
AType.SelectedItem.Text & "','" & _
BESTTIME.SelectedItem.Text & "','" & _
INT_PRICERANGE1.Text & "," & _
INT_PRICERANGE2.Text & "," & _
INT_LOCATION.Text & "','" & _
INT_WHEN.Text & "','" & _
PRODUCTS.Text & "')"



Tor BÃ¥dshaug said:
Well, if your code terminates like this (line 53) it is no wonder you get an
error. By using "& _" the compiler will expect another line of code. Your
code suggests there actually exists a line 54, but somehow it fell out? Post
your line 54 onwards and I will try to help.

Tor BÃ¥dshaug
tor.badshaug [//at\\] bekk.no.
Line 53:
"INT_PRICERANGE2,INT_LOCATION,INT_WHEN,PRODUCTS_PURCHASED) VALUES ('" & _
 
K

Kevin Spencer

If that is the code which threw the exception, and it is all one statement,
concatenating a bunch of strings together, then one of the references in the
code to an object must be a reference to an object that is null, Nothing, or
not initialized (the same meaning for all 3). Let's take it a step at a
time, so that next time you won't have to ask. First, you are concatenating
string literals, so that's not a problem. Second, you're adding in the Text
property of a number of form elements. As the Text property is always a
string, if only a blank string, that's not a problem either. Finally, you
are referencing the "SelectedItem" property of several listboxes. As this
property is initialized to null (Nothing), unless something changed the
SelectedItem, the exception would be thrown there.

Chances are, you can fix this by setting the SelectedItem property when you
initialize the ListBoxes.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

Ryan Smith said:
The error says Server Error in '/WebApp' Application

Object reference not set to an instance of an object
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object

It's like it has an issue with setting the string to the variable.... i'm
stumped!

Ryan Smith said:
Here is all of the code:

Dim strSQL As String = "INSERT INTO Investors
(FNAME,LNAME,EMAIL,ADDRESS1,ADDRESS2," & _

"CITY,STATE,ZIP,PNUMBER,ANUMBER,ATYPE,BESTTIME,INT_PRICERANGE1," & _

"INT_PRICERANGE2,INT_LOCATION,INT_WHEN,PRODUCTS_PURCHASED) VALUES ('" & _
FNAME.Text & "','" & _
LNAME.Text & "','" & _
EMAIL.Text & "','" & _
ADDRESS.Text & "','" & _
ADDRESS1.Text & "','" & _
CITY.Text & "','" & _
dState.SelectedItem.Text & "','" & _
ZIP.Text & "','" & _
PNUMBER.Text & "','" & _
ANUMBER.Text & "','" & _
AType.SelectedItem.Text & "','" & _
BESTTIME.SelectedItem.Text & "','" & _
INT_PRICERANGE1.Text & "," & _
INT_PRICERANGE2.Text & "," & _
INT_LOCATION.Text & "','" & _
INT_WHEN.Text & "','" & _
PRODUCTS.Text & "')"



Tor Bådshaug said:
Well, if your code terminates like this (line 53) it is no wonder you get an
error. By using "& _" the compiler will expect another line of code. Your
code suggests there actually exists a line 54, but somehow it fell out? Post
your line 54 onwards and I will try to help.

Tor Bådshaug
tor.badshaug [//at\\] bekk.no.

Line 53:
"INT_PRICERANGE2,INT_LOCATION,INT_WHEN,PRODUCTS_PURCHASED) VALUES ('" & _
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top