iT邦幫忙

0

如何用vb.net 寫再利用text查詢GridView裡面的ms sql欄位資料

Public Class WebForm4
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    SqlDataSource1.SelectCommand =
    "SELECT * FROM movie where" + RadioButtonList1.SelectedValue + " LIKE '%" + TextBox1.Text + "%'"
    GridView1.DataBind()
End Sub

End Class
目前的code
https://ithelp.ithome.com.tw/upload/images/20200505/20126870HikHULO4jd.png
預計的版面配置
目標是RadioButtonList1選定的項目與TextBox1輸入的內容來搜索
https://ithelp.ithome.com.tw/upload/images/20200505/20126870XipTLa0qGt.png
按下搜尋後變成這樣
希望高手解答

player iT邦大師 1 級 ‧ 2020-05-05 20:52:09 檢舉
1.這種寫法小心SQL資料隱碼
2.既然你有用SqlDataSource的話, 為何不在SqlDataSource1 裏去接控制項? 何必自組SelectCommand ?

1 個回答

我要發表回答

立即登入回答