0
我最近一直試圖找出一種方法來獲取參數化查詢的工作方式,我想我幾乎在那裏,但似乎在執行我的查詢時出現錯誤參數化查詢 - 執行查詢時出錯
下面是我調試它的代碼
Dim LogData2 As sterm.MarkData = New sterm.MarkData()
Dim query As String = ("Select * from openquery (db, 'SELECT * FROM table WHERE [email protected]')")
Dim cmd As New SqlCommand(query)
cmd.Parameters.AddWithValue("@investor", 34)
Dim drCode2a As DataSet = LogData2.StermQ3(query)
,它似乎並沒有打消參數到查詢。
"Select * from openquery (db, 'SELECT * FROM table WHERE [email protected]')"
這就是我得到當我調試線Dim drCode2a As DataSet = LogData2.StermQ3(query)
任何想法我做錯了嗎?
SOLUTION
以下是我解決我的問題
Dim conn As SqlConnection = New SqlConnection("server='h'; user id='w'; password='w'; database='w'; pooling='false'")
conn.Open()
Dim query As New SqlCommand("DECLARE @investor varchar(10), @sql varchar(1000) Select @investor = 69836 select @sql = 'SELECT * FROM OPENQUERY(db,''SELECT * FROM table WHERE investor = ''''' + @investor + ''''''')' EXEC(@sql)", conn)
dgBookings.DataSource = query.ExecuteReader
dgBookings.DataBind()
感謝您的幫助
我已經做了,但沒有'...'我得到'必須申報@ investor',如果我做它與'...'然後我得到'invlaid列前綴' – 2010-11-02 15:57:29
@Jamie泰勒看看我編輯的 – 2010-11-02 16:01:22
我現在越來越'屬性訪問必須分配給屬性或使用它的值.' – 2010-11-02 16:03:12