Link to home
Start Free TrialLog in
Avatar of NP2322
NP2322Flag for United States of America

asked on

Retrieving single piece of data from SQL database

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!
ASKER CERTIFIED SOLUTION
Avatar of ethoths
ethoths

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NP2322

ASKER

haven't tried using breakpoint yet, but it takes place in a button.
Avatar of badalpatel
badalpatel


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??
Avatar of NP2322

ASKER

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