Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

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!
0
NP2322
Asked:
NP2322
  • 2
1 Solution
 
ethothsCommented:
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
 
NP2322Author Commented:
haven't tried using breakpoint yet, but it takes place in a button.
0
 
badalpatelCommented:

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
 
NP2322Author Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now