I'm sure I must be missing something pretty basic or simple here, but I just can't see it !!!
I have a SQL-Server Table called
Locations
, with 2 Columns,
LocationKey
&
LocationPath
.
I have 1 record in that Table, the
LocationKey
=
LocationDespatchSchedules & the
LocationPath
=
D:\
My access to that table is via the following code :
Public Sub Get_Location(myFile As String, myType As String)
Dim mySqlConn As SqlConnection = New SqlConnection(myDB)
Dim mySqlString As String = "SELECT LocationPath FROM Locations WHERE LocationKey = 'Location" & myFile.Replace(" ", "") & "'"
Dim mySqlCmd As SqlCommand
Dim myObject As Object
Try
mySqlConn.Open()
mySqlCmd = New SqlCommand(mySqlString, mySqlConn)
myObject = mySqlCmd.ExecuteScalar()
If myObject IsNot Nothing Then
myFileLocation = myObject.ToString
Else
MessageBox.Show("Error - No Record Found")
End If
Catch ex As Exception
myAbortCode = "2"
MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
MessageBox.Show("Program Aborted")
Exit Sub
Finally
mySqlConn.Close()
End Try
End Sub
The value passed into
myFile
in this run is ...
Despatch Schedules
The value of mySqlCommand in the execution line is ...
SELECT LocationPath FROM Locations WHERE LocationKey = 'LocationDespatchSchedules'
As far as I can see, that is a match to the Key and it should therefore drop into the
myFileLocation
=
myObject.ToString line, but it doesn't, it returns Nothing and always falls through to the Error message.
What have I done wrong ?!?