T
Tmuld
(using vb.net)
Finally got paging working...not sorting taunts me...
For sorting on a datagrid - do you HAVE to use a dataview?
I used the msdn example and now get his error:
DataTable must be set prior to using DataView
So I have a dataset created from the input of the user and an SQL
statement. Then I use a dataview - well because I have to. The
dataview was made at design time along with the textbox and label.
Here is the code to generate and display my data retrieved:
Private Sub btnQuery_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn.Click
Dim Count As Integer
Dim ds As New DataSet
Dim SQL As String
SQL = "select [First],[Last],[Title],[Authors],[Address] from
DB1 WHERE [Title] LIKE '%" & txt.Text & "%'" & "OR [Address] LIKE '%" &
txt.Text & "%'" & " ORDER BY [Authors]"
Dim da As New SqlDataAdapter(SQL, SqlConnection2)
Try
SqlConnection2.Open()
da.Fill(ds)
Session("ds") = ds
Dim dv As DataView = ds.Tables(0).DefaultView
Count = dv.Count
dg.DataSource = dv
dg.DataBind()
lblCount.Text = Count
Catch ex As Exception
txtQuery.Text = ex.Message.ToString
Finally
SqlConnection2.Close()
End Try
End Sub
Private Sub dg_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
dg.SortCommand
dv.Sort = e.SortExpression
dg.DataBind()
End Sub
Where do I go from here? How do I add a Datatable? I know what the
columns are from my dataset?
Thanks!
Tmuld
Finally got paging working...not sorting taunts me...
For sorting on a datagrid - do you HAVE to use a dataview?
I used the msdn example and now get his error:
DataTable must be set prior to using DataView
So I have a dataset created from the input of the user and an SQL
statement. Then I use a dataview - well because I have to. The
dataview was made at design time along with the textbox and label.
Here is the code to generate and display my data retrieved:
Private Sub btnQuery_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn.Click
Dim Count As Integer
Dim ds As New DataSet
Dim SQL As String
SQL = "select [First],[Last],[Title],[Authors],[Address] from
DB1 WHERE [Title] LIKE '%" & txt.Text & "%'" & "OR [Address] LIKE '%" &
txt.Text & "%'" & " ORDER BY [Authors]"
Dim da As New SqlDataAdapter(SQL, SqlConnection2)
Try
SqlConnection2.Open()
da.Fill(ds)
Session("ds") = ds
Dim dv As DataView = ds.Tables(0).DefaultView
Count = dv.Count
dg.DataSource = dv
dg.DataBind()
lblCount.Text = Count
Catch ex As Exception
txtQuery.Text = ex.Message.ToString
Finally
SqlConnection2.Close()
End Try
End Sub
Private Sub dg_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
dg.SortCommand
dv.Sort = e.SortExpression
dg.DataBind()
End Sub
Where do I go from here? How do I add a Datatable? I know what the
columns are from my dataset?
Thanks!
Tmuld