Reputation: 107
i coppied some code from HERE but i'm getting an error: "incorrect syntax near ')'. But i can't see anything wrong with this code
Dim conString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\users.mdf;Integrated Security=True;User Instance=True"
Dim con As New SqlConnection(conString)
con.Open()
Try
Dim dataAdapter1 As New SqlDataAdapter( _
New SqlCommand("SELECT subject, info, username, status FROM(problems) WHERE (username =" & userName & ")", con))
Dim ds As New DataSet("DataSetMyProbs")
ds.Tables.Add("UserProbs")
dataAdapter1.Fill(ds.Tables("UserProbs")) '//This is where i get the error'
Me.bsMyProblems.DataSource = ds.Tables("UserProbs")
Dim dataAdapter2 As New SqlDataAdapter( _
New SqlCommand("SELECT dep, pcid, username, status, extraInfo FROM(deployments) WHERE (username = " & userName & ")", con))
ds.Tables.Add("UsersDepl")
dataAdapter2.Fill(ds.Tables("UserDepl"))
Me.bsMyDepl.DataSource = ds.Tables("UserDepl")
Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
con.Dispose()
End Try
Upvotes: 0
Views: 756
Reputation: 1128
I assume that may because of your query, is your parameter userName a string? you may need to put a single quote for a string, also give a space in between "FROM" and the table name
Dim dataAdapter1 As New SqlDataAdapter( _
New SqlCommand("SELECT subject, info, username, status FROM [problems] WHERE (username ='" & userName & "')", con))
Upvotes: 1
Reputation: 5340
the problem is in your SQL statement
It should be:
SELECT subject, info, username, status FROM [problems] ....
Upvotes: 0