In your SQL statement you cannot select only ClientID. Select is for you column in the table. if you have the 2 columns fundingsource1 and 2 and the clientid and you want to see if clientid is those 2 columns then you write something like this
"SELECT fundingsource1, fundingsource2 WHERE (fundingsource1=@clientid) or (fundingsource2=@clientid)"
if the table has more than 2 columns and you need access to the data in all of them then you can write something like this
"SELECT * WHERE (fundingsource1=@clientid) or (fundingsource2=@clientid)"
This is a class is use with MS SQL servers. I actually have more functions in the class for stuff I do all the time. I don't like re-writing lines of codes. If you want to understand the newID and execscalar then read about execscalar.
You can use it in your project like this and change the connection string to match yours
sub Something ()
Dim xDB as new dbcontrol
dim SQLQuery as string = "SELECT fundingsource1, fundingsource2 WHERE (fundingsource1=@clientid) or (fundingsource2=@clientid)"
xdb.addparams("@clientid",ClientID)
xdb.execquery(SQLQuery)
end sub
SQL DBControl class
Imports System.Data.SqlClient
Public Class DBControl
' CREATE YOUR DB CONNECTION
'Change the datasource
Public SQLSource As String = "Data Source=someserver\sqlexpress;Integrated Security=True"
Private DBCon As New SqlConnection(SQLSource)
' PREPARE DB COMMAND
Private DBCmd As SqlCommand
' DB DATA
Public DBDA As SqlDataAdapter
Public DBDT As DataTable
' QUERY PARAMETERS
Public Params As New List(Of SqlParameter)
' QUERY STATISTICS
Public RecordCount As Integer
Public Exception As String
Public Sub ExecQuery(Query As String, Optional ByVal ExecScalar As Boolean = False, Optional ByRef NewID As Long = -1)
' RESET QUERY STATS
RecordCount = 0
Exception = ""
Try
' OPEN A CONNECTION
DBCon.Open()
' CREATE DB COMMAND
DBCmd = New SqlCommand(Query, DBCon)
' LOAD PARAMS INTO DB COMMAND
Params.ForEach(Sub(p) DBCmd.Parameters.Add(p))
' CLEAR PARAMS LIST
Params.Clear()
' EXECUTE COMMAND & FILL DATATABLE
If ExecScalar = True Then
NewID = DBCmd.ExecuteScalar()
End If
DBDT = New DataTable
DBDA = New SqlDataAdapter(DBCmd)
RecordCount = DBDA.Fill(DBDT)
Catch ex As Exception
Exception = ex.Message
End Try
' CLOSE YOUR CONNECTION
If DBCon.State = ConnectionState.Open Then DBCon.Close()
End Sub
' INCLUDE QUERY & COMMAND PARAMETERS
Public Sub AddParam(Name As String, Value As Object)
Dim NewParam As New SqlParameter(Name, Value)
Params.Add(NewParam)
End Sub
End Class