NP2322
asked on
Retrieving single piece of data from SQL database
I have this little snippet of code:
myconnectionstring = "Data Source=.\SQLEXPRESS;Attach DbFilename =|DataDire ctory|\ASP NETDB.MDF; Integrated Security=True;User Instance=True"
Dim myconn As New Data.SqlClient.SqlConnecti on(myconne ctionstrin g)
myconn.Open()
Dim objcommand1 As New Data.SqlClient.SqlCommand( "SELECT RTRIM(aspnet_ChamberWorkst ation.Work station) AS Expr1 FROM aspnet_ZoneChamber INNER JOIN aspnet_ChamberWorkstation ON aspnet_ZoneChamber.Zone = aspnet_ChamberWorkstation. Zone WHERE (aspnet_ZoneChamber.Chambe r = '" & Me.DropDownList1.SelectedV alue & "') AND aspnet_ChamberWorkstation. workstatio n = '" & 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!
myconnectionstring = "Data Source=.\SQLEXPRESS;Attach
Dim myconn As New Data.SqlClient.SqlConnecti
myconn.Open()
Dim objcommand1 As New Data.SqlClient.SqlCommand(
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
Please Help!
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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??
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
Thanks,
Nikhul
ASKER