我处理了一些来自的代码,但是我得到了一个错误:“语法错误”。
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发布于 2012-05-08 01:53:33
我假设可能因为您的查询,参数userName是字符串吗?您可能需要为字符串添加一个单引号,还需要在"FROM“和表名之间留出一个空格。
Dim dataAdapter1 As New SqlDataAdapter( _
New SqlCommand("SELECT subject, info, username, status FROM [problems] WHERE (username ='" & userName & "')", con))发布于 2012-05-08 01:53:18
问题在SQL语句中。
它应该是:
SELECT subject, info, username, status FROM [problems] ....https://stackoverflow.com/questions/10491477
复制相似问题