下拉菜单的问题!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim notice As String = "notice_infor" & DropDownList1.SelectedItem.Text sh = DropDownList1.SelectedItem.Text
Dim student_id As String = HttpUtility.UrlDecode(Request.Cookies("userInf").Values("userID"))
Dim dsn As String = ConfigurationSettings.AppSettings("DSN_student")
Dim conn As New SqlClient.SqlConnection
conn.ConnectionString = dsn
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = conn
Dim ds1 As DataSet = New DataSet
Dim mydap1 As New SqlClient.SqlDataAdapter
cmd.CommandText = "SELECT n_id,n_title,nu_date1,nu_student FROM " & notice & "" mydap1.SelectCommand = cmd
Try
conn.Open()
mydap1.Fill(ds1, "teachingnotice")
DataGrid1.DataSource = ds1.Tables("teachingnotice")
DataGrid1.DataBind()
Catch
Label1.Text = "错误!"
Finally
conn.Close()
End Try
End Sub
也就是我想从下拉菜单的内容,动态的查询数据库,现在就没有用了!
--------------------编程问答-------------------- 你有什么问题呢
--------------------编程问答-------------------- 我的问题是现在只能查第一行的数据库,从下拉菜单选第二行就没有用了! --------------------编程问答-------------------- 没看到你的Where语句在那里啊!!!!!!!!!
cmd.CommandText 和 notice 合并起来是
SELECT n_id,n_title,nu_date1,nu_student FROM notice_infor" & DropDownList1.SelectedItem.Text
where呢? 应该是
SELECT n_id,n_title,nu_date1,nu_student FROM notice_infor where n_title ='" & DropDownList1.SelectedItem.Text & "'"
'或者是其他字段
--------------------编程问答-------------------- 晕,少加了引号,最后结果应该是
--------------------编程问答-------------------- 楼上正解。。你的查询语句只是在数据库查询n_id,n_title,nu_date1,nu_student 这几个字段下面的所有值,缺少定位语句,
cmd.CommandText="SELECT n_id,n_title,nu_date1,nu_student FROM notice_infor where n_title ='" & DropDownList1.SelectedItem.Text & "'"
'或者是其他字段
应加入WHERE语句 --------------------编程问答-------------------- 以后需再关注,现在先帮你顶一下
补充:.NET技术 , VB.NET