Solved

Retrieving single piece of data from SQL database

Posted on 2006-11-14
4
197 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

713 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