C#做一个按名称的首字母的模糊查询
比如按下按钮A在dataGridView中就出现所有名字拼音开头为A的人相关的信息。……在线等,谢谢我的数据库里只有名字(汉字),也用字母?应该不是吧?那怎么办?再给每个...
比如按下按钮A在dataGridView中就出现所有名字拼音开头为A的人相关的信息。
……
在线等,谢谢
我的数据库里只有名字(汉字),也用字母?
应该不是吧?
那怎么办?
再给每个人名后面加一列汉语拼音吗? 展开
……
在线等,谢谢
我的数据库里只有名字(汉字),也用字母?
应该不是吧?
那怎么办?
再给每个人名后面加一列汉语拼音吗? 展开
4个回答
展开全部
这个我做过, 下面代码实现的是在用户输入一个字母时候,鼠标就定位到以该字母的那一行,如果再按一次还可以定位到下一行。实例是以Name列来演示的。
Private Sub OnGridViewKeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DataGridViewProcess.KeyPress
' Get the key char.
Dim pressedChar As Char = Char.ToLower(e.KeyChar)
' Get all the rearch result.
Dim strName As String = String.Empty
For Each dc As DataGridViewColumn In DataGridViewProcess.Columns
If dc.HeaderText.ToLower() = "name" Then
strName = dc.Name
Exit For
End If
Next
' If not find the name column, just return.
If String.IsNullOrEmpty(strName) Then
Exit Sub
End If
Dim searchResult As List(Of DataGridViewRow) = New List(Of DataGridViewRow)
For Each dr As DataGridViewRow In DataGridViewProcess.Rows
If dr.Cells(strName).Value.ToString.ToLower().StartsWith(pressedChar) Then
searchResult.Add(dr)
End If
Next
' Clear all the selected rows
Dim selectedRow As DataGridViewRow = Nothing
Dim findNext As Boolean = False
If DataGridViewProcess.SelectedRows.Count > 0 Then
selectedRow = DataGridViewProcess.SelectedRows(0)
End If
DataGridViewProcess.ClearSelection()
' First, we try to locate the next row after current row.
If selectedRow IsNot Nothing Then
For Each dr As DataGridViewRow In searchResult
If dr.Index > selectedRow.Index Then
findNext = True
dr.Selected = True
DataGridViewProcess.FirstDisplayedScrollingRowIndex = dr.Index
Exit For
End If
Next
End If
' Second, if not find the next row, we try to locate the next row before current row.
If Not findNext Then
For Each dr As DataGridViewRow In searchResult
findNext = True
dr.Selected = True
DataGridViewProcess.FirstDisplayedScrollingRowIndex = dr.Index
Exit For
Next
End If
End Sub
Private Sub OnGridViewKeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DataGridViewProcess.KeyPress
' Get the key char.
Dim pressedChar As Char = Char.ToLower(e.KeyChar)
' Get all the rearch result.
Dim strName As String = String.Empty
For Each dc As DataGridViewColumn In DataGridViewProcess.Columns
If dc.HeaderText.ToLower() = "name" Then
strName = dc.Name
Exit For
End If
Next
' If not find the name column, just return.
If String.IsNullOrEmpty(strName) Then
Exit Sub
End If
Dim searchResult As List(Of DataGridViewRow) = New List(Of DataGridViewRow)
For Each dr As DataGridViewRow In DataGridViewProcess.Rows
If dr.Cells(strName).Value.ToString.ToLower().StartsWith(pressedChar) Then
searchResult.Add(dr)
End If
Next
' Clear all the selected rows
Dim selectedRow As DataGridViewRow = Nothing
Dim findNext As Boolean = False
If DataGridViewProcess.SelectedRows.Count > 0 Then
selectedRow = DataGridViewProcess.SelectedRows(0)
End If
DataGridViewProcess.ClearSelection()
' First, we try to locate the next row after current row.
If selectedRow IsNot Nothing Then
For Each dr As DataGridViewRow In searchResult
If dr.Index > selectedRow.Index Then
findNext = True
dr.Selected = True
DataGridViewProcess.FirstDisplayedScrollingRowIndex = dr.Index
Exit For
End If
Next
End If
' Second, if not find the next row, we try to locate the next row before current row.
If Not findNext Then
For Each dr As DataGridViewRow In searchResult
findNext = True
dr.Selected = True
DataGridViewProcess.FirstDisplayedScrollingRowIndex = dr.Index
Exit For
Next
End If
End Sub
展开全部
select count(0) from sysobjects where id=object_id(N'表名') and objectproperty(id,N'IsUserTable')=1
如果返回的是0,则不存在,1为存在。
如果返回的是0,则不存在,1为存在。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
sql语句写成这样就行了:select * from table_name where name like 'A%';
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
点按钮的时候用SQL在后台做一次模糊检索好了
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询