1. Protected SQLAdapter As SqlDataAdapter Protected DSet As New DataSet
Protected DView As DataView
Protected BMCategoryGRD As BindingManagerBase
Protected Const STR_TableName As String = "ITR"
Private Str_RowFilter As String = ""
Private Str_RowFilterQuery As String = Str_RowFilter'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 尝试连接到SQL数据库中
Dim IsConnecting As Boolean = True
While IsConnecting = True
Try
DSet.Tables.Clear() Dim connection As New SqlConnection(str_Connection)
Dim strSQL As String = _
"SELECT * " & _
"FROM ITR " If Str_RowFilterQuery <> "" Then
strSQL &= "Where " & Str_RowFilterQuery
End If
'Console.WriteLine(strSQL) Dim sqlcmd As New SqlCommand(strSQL, connection)
SQLAdapter = New SqlDataAdapter(sqlcmd)
SQLAdapter.Fill(DSet, STR_TableName)
DView = New DataView(DSet.Tables(STR_TableName), "", "", DataViewRowState.OriginalRows)
' 连接成功后发出退出loop循环的信息
IsConnecting = False
Catch exc As Exception
MessageBox.Show("连接数据库失败")
Exit Sub
Finally
End Try
End While GRD.DataSource = DSet.Tables(STR_TableName)
GRD.ReadOnly = True
Protected DView As DataView
Protected BMCategoryGRD As BindingManagerBase
Protected Const STR_TableName As String = "ITR"
Private Str_RowFilter As String = ""
Private Str_RowFilterQuery As String = Str_RowFilter'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 尝试连接到SQL数据库中
Dim IsConnecting As Boolean = True
While IsConnecting = True
Try
DSet.Tables.Clear() Dim connection As New SqlConnection(str_Connection)
Dim strSQL As String = _
"SELECT * " & _
"FROM ITR " If Str_RowFilterQuery <> "" Then
strSQL &= "Where " & Str_RowFilterQuery
End If
'Console.WriteLine(strSQL) Dim sqlcmd As New SqlCommand(strSQL, connection)
SQLAdapter = New SqlDataAdapter(sqlcmd)
SQLAdapter.Fill(DSet, STR_TableName)
DView = New DataView(DSet.Tables(STR_TableName), "", "", DataViewRowState.OriginalRows)
' 连接成功后发出退出loop循环的信息
IsConnecting = False
Catch exc As Exception
MessageBox.Show("连接数据库失败")
Exit Sub
Finally
End Try
End While GRD.DataSource = DSet.Tables(STR_TableName)
GRD.ReadOnly = True
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货