Reputation: 29
This is my sql server select query in vb.net.
Try
retrieveRecord("ProductBasicInfo", "ProdID = " & txtProdID.Text.Trim)
DataGridView1.DataSource = dsSql.Tables("ProductBasicInfo")
MessageBox.Show("ok")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
and this is the function which receives the query:
Public Sub retrieveRecord(ByVal tblname As String, ByVal parameter As String)
Try
If dsSql.Tables.Contains(tblname) Then
dsSql.Tables.Remove(tblname)
End If
cmdSql1.CommandText = "select * from " & tblname & "where " & parameter & ""
cmdSql1.Connection = Connect()
daSql.SelectCommand = cmdSql1
daSql.Fill(dsSql, tblname)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
It gives error that incorrect syntax near =? Please guide me that where i am doing mistake.
Upvotes: 1
Views: 84
Reputation: 5647
You need a space between tblname and where and you probably want quotes around txtProdID.Text.Trim.
Upvotes: 0
Reputation: 2295
In generating your SQL statement
cmdSql1.CommandText = "select * from " & tblname & "where " & parameter & ""
You are neglecting to insert a space between the table name and your WHERE clause....
cmdSql1.CommandText = "select * from " & tblname & " where " & parameter & ""
...also, the ending & "" is moot, extraneous.
Upvotes: 3