您的位置:首页 > 博客中心 > 数据库 >

利用SQL处理DataGrid表格问题

时间:2022-03-10 17:27

Private Sub btnQuery_Click(sender As Object, e As EventArgs) Handles btnQuery.Click '验证 两个文本框中是否为空 Dim MyObject As New UIcommonFunction If MyObject.verifyNull(Controls) = False Then Exit Sub End If Dim queryBll As New BLL.SqlQueryRecordBLL Try Dim dtRechargeLog As New DataTable dtRechargeLog = queryBll.QueryRechargeLog(txtCardNo.Text) dataGrid.DataSource = dtRechargeLog Catch ex As Exception MessageBox.Show(ex.Message.ToString()) End Try End Sub

''' <summary> ''' 验证文本框是否为空 ''' </summary> ''' <param name="log"></param> ''' <returns></returns> ''' <remarks></remarks> Public Function verifyNull(log As Windows.Forms.Control.ControlCollection) As Boolean Dim objCon As New Control Dim flag As Boolean = True '默认 所有文本框都不为空 '开始检测每个控件 是否为空的判断 For Each objCon In log If TypeOf (objCon) Is TextBox And objCon.Visible = True Then If objCon.Text = "" Then MsgBox(objCon.Tag.ToString & " 不能为空,请输入完整", vbOKOnly, "提示") objCon.Focus() flag = False Return flag End If ElseIf TypeOf (objCon) Is ComboBox And objCon.Visible = True Then If objCon.Text = "" Then MsgBox(objCon.Tag.ToString & " 不能为空,请输入完整", vbOKOnly, "提示") objCon.Focus() flag = False Return flag End If End If Next objCon Return True End Function

''' <summary> ''' 获取充值记录 ''' </summary> ''' <param name="cardNo"></param> ''' <returns></returns> ''' <remarks></remarks> Public Function QueryRechargeLog(cardNo As String) As DataTable Dim iStudent As IDAL.IStudent iStudent = Factory.DBFactory.CreateStudent Dim iRechargeLog As IDAL.IRechargeLog iRechargeLog = Factory.DBFactory.CreateRechargeLog Dim dtStudent As New DataTable dtStudent = iStudent.QueryStudent(cardNo) '验证用户的卡号是否存在 If dtStudent.Rows.Count = 0 Then Throw New Exception("卡号不存在") End If Dim dtRechargeLog As New DataTable dtRechargeLog = iRechargeLog.GetRechargeLog(cardNo) Return dtRechargeLog End Function

''' <summary> ''' 查询指定时间段内的 收取金额 ''' </summary> ''' <param name="stime">开始日期</param> ''' <param name="etime">终止日期</param> ''' <returns></returns> ''' <remarks></remarks> Public Function GetRechargeInDate(stime As String, etime As String) As DataTable Implements IDAL.IRechargeLog.GetRechargeInDate Dim strSQL As String = "select identity(int,1,1) as 序号,cardNo as 卡号,addCash as 充值金额,date as 日期,time as 时间,UserId as 操作人,status as 状态 into #1 from Recharge_Info where date between @sTime and @eTime select * from #1 drop table #1" Dim sqlparams As SqlParameter() = {New SqlParameter("@sTime", stime), New SqlParameter("@eTime", etime)} Dim helper As New SqlHelper Dim dtRechargelog As New DataTable dtRechargelog = helper.Query(strSQL, CommandType.Text, sqlparams) Return dtRechargelog End Function


接口与工厂,与上个Demo类似,自行补充吧。

 

     DataGridView作为一个表格控件,可以事先设计好模版,之后显示,也可以仅仅作为一个容器来使用。sql语句可以处理的事情有很多,完全可以后台处理之后直接显示。

       有很多对表操作的地方,都可以用sql处理里面的知识解决。 视图 虚拟表就和很好的应用。

利用SQL处理DataGrid表格问题,布布扣,bubuko.com

热门排行

今日推荐

热门手游