Please help it's really annoying me now!!!!
I need the following code to display a list in the first box with items from the database, which when clicked, display the correct information in the datagrid. I can't see why it wont work! (Please ignore stars - this is not the problem)
Imports System.Data.SqlClient
Public Class droptest
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'Connect to database
Dim myconnection As SqlConnection
Dim myda As SqlDataAdapter
Dim ds As DataSet
myconnection = New SqlConnection("workstation id=****;packet size=4096;integrated security=SSPI;data source=""****/****"";persist security info=False;initial catalog=name")
myda = New SqlDataAdapter("Select DISTINCT * from name ", myconnection)
ds = New DataSet
myda.Fill(ds, "name")
'Populate list with categories from database
DropDownList1.DataSource = ds
DropDownList1.DataSource = ds.Tables(0)
DropDownList1.DataTextField = ds.Tables(0).Columns("Category").ColumnName.ToString()
DropDownList1.DataValueField = ds.Tables(0).Columns("Category").ColumnName.ToString()
DropDownList1.DataBind()
End Sub
End Class
Public Class question
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myDataset As New DataSet
'Display results in grid according to selection
Dim DS As DataSet
DS = New DataSet
SqlDataAdapter1.SelectCommand.CommandText = "SELECT * FROM name WHERE Category='" & DropDownList1.SelectedValue & "'"
SqlDataAdapter1.Fill(DS, "name")
DataGrid1.DataSource = DS.Tables("name").DefaultView
DataGrid1.DataBind()
End Sub
End ClassoK SORTED NOW
I need the following code to display a list in the first box with items from the database, which when clicked, display the correct information in the datagrid. I can't see why it wont work! (Please ignore stars - this is not the problem)
Imports System.Data.SqlClient
Public Class droptest
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'Connect to database
Dim myconnection As SqlConnection
Dim myda As SqlDataAdapter
Dim ds As DataSet
myconnection = New SqlConnection("workstation id=****;packet size=4096;integrated security=SSPI;data source=""****/****"";persist security info=False;initial catalog=name")
myda = New SqlDataAdapter("Select DISTINCT * from name ", myconnection)
ds = New DataSet
myda.Fill(ds, "name")
'Populate list with categories from database
DropDownList1.DataSource = ds
DropDownList1.DataSource = ds.Tables(0)
DropDownList1.DataTextField = ds.Tables(0).Columns("Category").ColumnName.ToString()
DropDownList1.DataValueField = ds.Tables(0).Columns("Category").ColumnName.ToString()
DropDownList1.DataBind()
End Sub
End Class
Public Class question
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myDataset As New DataSet
'Display results in grid according to selection
Dim DS As DataSet
DS = New DataSet
SqlDataAdapter1.SelectCommand.CommandText = "SELECT * FROM name WHERE Category='" & DropDownList1.SelectedValue & "'"
SqlDataAdapter1.Fill(DS, "name")
DataGrid1.DataSource = DS.Tables("name").DefaultView
DataGrid1.DataBind()
End Sub
End ClassoK SORTED NOW