Problem with sql statements.

Public Function GetUserEntries(ByVal userID As String) As DataSet
        Dim sql As New StringBuilder()
        sql.AppendLine("SELECT t.typeid as AppID, i.interviewid, t.Name AS Application, i.PrimaryUse AS [Primary Use], i.DateLastModified AS [Date Last Modified], ")
        sql.AppendLine(" (SELECT  COUNT(*) FROM   tbl_dotnet_attachments AS a WHERE  (i.InterviewID = InterviewID)) AS Attachements FROM  tbl_dotnet_interviews AS i INNER JOIN ")
        sql.AppendLine(" tbl_dotnet_types AS t ON i.AppID = t.TypeID WHERE(i.szName = " + userID + ")")
        Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim ds As New DataSet()
        Dim da As New SqlDataAdapter(sql.ToString(), conn)
        da.Fill(ds, "APPS")
        Return ds
    End Function

            sql.ToString()      
"SELECT t.typeid as AppID, i.interviewid, t.Name AS Application, i.PrimaryUse AS [Primary Use], i.DateLastModified AS [Date Last Modified],
 (SELECT  COUNT(*) FROM   tbl_dotnet_attachments AS a WHERE  (i.InterviewID = InterviewID)) AS Attachements FROM  tbl_dotnet_interviews AS i INNER JOIN
 tbl_dotnet_types AS t ON i.AppID = t.TypeID WHERE(i.szName = matt)
"      String


 exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: Invalid column name 'matt'.

the problem is that i.szName is null so I still want the quire to work.
mathieu_cuprykAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jandromedaCommented:
Your code should change like this.

Public Function GetUserEntries(ByVal userID As String) As DataSet
        Dim sql As New StringBuilder()
        sql.AppendLine("SELECT t.typeid as AppID, i.interviewid, t.Name AS Application, i.PrimaryUse AS [Primary Use], i.DateLastModified AS [Date Last Modified], ")
        sql.AppendLine(" (SELECT  COUNT(*) FROM   tbl_dotnet_attachments AS a WHERE  (i.InterviewID = InterviewID)) AS Attachements FROM  tbl_dotnet_interviews AS i INNER JOIN ")
        sql.AppendLine(" tbl_dotnet_types AS t ON i.AppID = t.TypeID WHERE(i.szName = '" + userID + "')")
        Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim ds As New DataSet()
        Dim da As New SqlDataAdapter(sql.ToString(), conn)
        da.Fill(ds, "APPS")
        Return ds
    End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mathieu_cuprykAuthor Commented:
i think i need single quotes?
0
jandromedaCommented:
Yeah. Since it is a string.
0
mathieu_cuprykAuthor Commented:
cool
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.