16,555
社区成员
发帖
与我相关
我的任务
分享
Public Function GetDataSet(ByVal strSQL As String) As DataSet
Dim ds As DataSet = New DataSet '聲明數據表 Dim ds As New DataSet
Try
'初始化適配器
Dim da As SqlDataAdapter
'打開數據庫鏈接
If g_CN Is Nothing Then
GetConnection()
End If
ds.Clear()
'將數據庫和適配器鏈接在一起
da = New SqlDataAdapter(strSQL, g_CN)
'將數據放到數據集中
da.Fill(ds)
Return ds
Catch ex As Exception
MessageBox.Show("GetDataSet出错!")
End Try
Return ds
End Function
strSQL = "SELECT * FROM VWEmployees WHERE DepID like '%" & trvData.SelectedNode.Name & "%' order by EmpID"
Dim ds As DataSet = GetDataSet(strSQL)
If ds.Tables.Item(0).Rows.Count = 0 Then
MessageBox.Show("资料不存在")
Else
'显示数据
Me.dgvShowData.DataSource = ds.Tables.Item(0).DefaultView
'中文标题
chineseTitle()
End If
Try
parentPage.TreeView1.Enabled = True
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End If
Public Function quaryUser() As Boolean
'判断窗体是否为空
Dim strSql As String = ""
If cmbUid.Text = "" Or txtPwd.Text = "" Then
MessageBox.Show("帐号或密碼不能為空!")
Return False
'獲取數據庫鏈接
Else
'校驗密碼和用戶名的SQL語句
strSql = "SELECT * FROM Users WHERE UserID = '" + cmbUid.Text + "' AND PASSWORD = '" + txtPwd.Text + "'"
Dim dt As DataTable = cls.GetDataTable(strSql) '模块的方法在此的调用 给你发下面
If dt.Rows.Count = 0 Then
MessageBox.Show("密碼或用戶名錯誤!", "錯誤提示!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
Else
Try
parentPage.TreeView1.Enabled = True
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End If
End If
End Function
'执行查询,并将查询结果封装成DataTable
Public Function GetDataTable(ByVal strSQL As String) As DataTable
Dim dtTable As New DataTable
Dim daAper As SqlDataAdapter
Dim gCN As SqlConnection = GetConnection()
daAper = New SqlDataAdapter(strSQL, gCN)
daAper.Fill(dtTable)
GetDataTable = dtTable
gCN.Close()
gCN = Nothing
End Function
str = "select Count(*) as count from mytb where username='" & txt1& "' and password='" & txt2 & "'"
str = "select username,password from mytb where username='" & txt1& "' and password='" & txt2 & "'"
If ds.Tables.Item(0).Rows.Count > 0 Then
lblExpand.Text = lblExpand.Text & " 考号:" & (ds.Tables(0).Rows(0)(0).ToString)
lblExpand.Text = lblExpand.Text & " 姓名:" & (ds.Tables(0).Rows(0)(1).ToString)
'密码栏位
'lblExpand.Text = lblExpand.Text & " 密码:" & (ds.Tables(0).Rows(0)(2).ToString)
'性别处理
Dim strSex As String = ""
If ds.Tables(0).Rows(0)(3).ToString = "1" Then
strSex = "男"
Else
strSex = "女"
End If
lblExpand.Text = lblExpand.Text & " 性别:" & strSex
End If
ds.Tables(0).Rows(0)(0).ToString