Posts tagged sql
Filtering a datagridview
0assuming you have a datagridview that has data in it.
you want to avoid recalling sql from the database & just want to filter the datagrid.
you can do the following, What you need (1 datagridview (data), 1 button (search), 1 textbox (string to search), 1 variable to precise the criteria your searching for)
Dim findcrit as string
Dim dt As DataTable = Ds_Pos.Employees
Dim dv As New DataView(dt)
Dim _RowFilter As String = ""
Dim _FieldType = dt.Columns(findcrit).DataType.ToString
Select Case _FieldType
Case "System.Int32"
_RowFilter = "convert(" & findcrit & ", 'System.String') like '" & Me.TextBox1.Text & "'"
Case "System.Int64"
_RowFilter = "convert(" & findcrit & ", 'System.String') like '" & Me.TextBox1.Text & "'"
Case "System.Double"
_RowFilter = "convert(" & findcrit & ", 'System.String') like '" & Me.TextBox1.Text & "'"
Case "System.String"
_RowFilter = findcrit & " like '" & TextBox1.Text & "*'"
End Select
dv.RowFilter = _RowFilter
EmployeesDataGridView.DataSource = dv
The cases are to cast the type of variable from any type to string because you can only use the method on string data types.
the idea is to move the content to a data table then filter then return it back to the datatable.
SQL 2008 – Change “Edit Top 200 Rows”
3Well this is a great idea from Microsoft, but what if you want them all , or you want more then 200 rows like me , I am greedy , I like everything….
Any ways I was prepared to hack the registry for this one , but it seems you don’t really have to , and its in very simple to do and find…
Lesson 1 learned, late nights and SQL don’t mix.
Lesson 2 Change the Top 200 rows
go to:
Tools -> Options ->SQL Server Object Explorer, Expand this tree
Choose ‘Commands’
And there you go change it to your desired amount, 0 = everything!
This is the youtube link for my demonstration :
Best Regards.
Rabih Tawil