Solved

Retrieving single piece of data from SQL database

Posted on 2006-11-14
4
196 Views
Last Modified: 2012-06-21
I have this little snippet of code:

        myconnectionstring = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
        Dim myconn As New Data.SqlClient.SqlConnection(myconnectionstring)
        myconn.Open()
        Dim objcommand1 As New Data.SqlClient.SqlCommand("SELECT RTRIM(aspnet_ChamberWorkstation.Workstation) AS Expr1 FROM aspnet_ZoneChamber INNER JOIN aspnet_ChamberWorkstation ON aspnet_ZoneChamber.Zone = aspnet_ChamberWorkstation.Zone WHERE (aspnet_ZoneChamber.Chamber = '" & Me.DropDownList1.SelectedValue & "') AND aspnet_ChamberWorkstation.workstation = '" & objWSHNetwork.ComputerName & "'", myconn)
        workstationcheck = objcommand1.ExecuteScalar
        MsgBox(workstationcheck)

I'm trying to pull a single piece of data from the database which DOES exist. When the msgbox triggers, it is suppose to show the name of the workstation is pulls from the database, but in this case the box is just blank. I'm sure it's got something to so with my SQL statement but i can't figure out what i'm doing wrong.

Just as a heads up, objWSHNetwork.ComputerName, pulls the name of the workstation i am running on. I'm trying to do a verification with the database to make sure that the workstation I am currently on is listed as a secure workstation in the SQL database.

Please Help!

Thanks!
0
Comment
Question by:NP2322
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
ethoths earned 500 total points
ID: 17939903
Put a breakpoint on Me.DropDownList1.SelectedValue and see what value is being pushed up.

Where in the page lifecycle are you doing this (init, load, prerender...)?

0
 

Author Comment

by:NP2322
ID: 17940321
haven't tried using breakpoint yet, but it takes place in a button.
0
 
LVL 6

Expert Comment

by:badalpatel
ID: 17945443

i think ur query is not returning any data and thats readon the message box is blank..
try to execute the query in query analyzer and see what happened, is it giving data??
0
 

Author Comment

by:NP2322
ID: 17950735
i was able to figure it out. it was definitely in the SQL statement. I was comparing a string to a number in my WHERE clause. IDIOT.

Thanks,
Nikhul
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question