-2
我创建了这个查询,但我不知道如何将它绑定到sqldatasource,所以我可以创建一个datalist,有人可以帮我吗?SQL查询到SQL数据源
Dim cn As SqlConnection = New SqlConnection()
Dim cmd As SqlCommand = New SqlCommand()
Dim dr As SqlDataReader
If Session("Email") <> "" Then
cn.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
cmd.Connection = cn
cmd.CommandText = "Select Name From [Games] Where Platform = @Platform AND Genre = @Genre AND Age >= @Age"
Dim Platform As New SqlParameter("@Platform", SqlDbType.VarChar, 20)
Platform.Value = ddlPlatform.SelectedItem.ToString()
cmd.Parameters.Add(Platform)
Dim Genre As New SqlParameter("@Platform", SqlDbType.VarChar, 20)
Genre.Value = ddlgenre.SelectedItem.ToString()
cmd.Parameters.Add(Genre)
Dim Age As New SqlParameter("@Age", SqlDbType.Int)
Age.Value = txtAge.Text.ToString()
cmd.Parameters.Add(Age)
'Open the connection to the database
cn.Open()
' Execute the sql.
dr = cmd.ExecuteReader()`
你能说出你的问题显然 –
对不起,我需要在DataList控件来显示这个查询的结果,我不知道怎么回事,我只用过的SqlDataSource。 – Alexandria
看看这个链接http://msdn.microsoft.com/en-us/library/aa719635(v=vs.71).aspx –