16,717
社区成员
发帖
与我相关
我的任务
分享If tf = True Or rbut_all.Checked = True Then
Dim cmd As String
cmd = "select [id],[class],[smallclass],[type],[add],[username],[condition],[bm],[data],[bz] from zcinfo"
If rbut_all.Checked = True Then
'==============打开selectview窗口并且传递sqlcmd
selectview.sqlcmd = cmd
Else
If chb_bm.Checked = False And chb_class.Checked = False And chb_data.Checked = False _
And chb_name.Checked = False And chb_smallclass.Checked = False And chb_xh.Checked = False _
And chb_zt.Checked = False Then
'selectview.sqlcmd = cmd
Else
cmd = "select [id],[class],[smallclass],[type],[add],[username],[condition],[bm],[data],[bz] from zcinfo where "
End If
'==============组合sql语句为给sqlcmd传递服务
'==检测大类是否被选中
Dim pdtf As Boolean
pdtf = False
If chb_class.Checked = True Then
pdtf = True
cmd += "class=" + (cb_class.SelectedIndex + 1).ToString()
End If
'==检测存放地边是否被选中
If chb_sybm.Checked = True Then
If pdtf = False Then
cmd += "[add]='" + txt_sybm.Text + "'"
pdtf = True
Else
cmd += " and [add]='" + txt_sybm.Text + "'"
End If
End If
'==检测小类是否被选中
If chb_smallclass.Checked = True Then
If pdtf = False Then
cmd += "smallclass=" + (cb_smallclass.SelectedIndex + 1).ToString()
pdtf = True
Else
cmd += " and smallclass=" + (cb_smallclass.SelectedIndex + 1).ToString()
End If
End If
'==检测型号是否被选中
If chb_xh.Checked = True Then
If pdtf = False Then
cmd += "type='" + txt_xh.Text + "'"
pdtf = True
Else
cmd += " and type='" + txt_xh.Text + "'"
End If
End If
'==检测部门是否被选中
If chb_bm.Checked = True Then
If pdtf = False Then
cmd += "bm=" + (cb_bm.SelectedIndex + 1).ToString()
pdtf = True
Else
cmd += " and bm=" + (cb_bm.SelectedIndex + 1).ToString()
End If
End If
'==检测姓名是否被选中
If chb_name.Checked = True Then
If pdtf = False Then
cmd += "username='" + txt_name.Text + "'"
pdtf = True
Else
cmd += " and username='" + txt_name.Text + "'"
End If
End If
'==检测状态是否被选中
If chb_zt.Checked = True Then
If pdtf = False Then
'cmd += "[condition]=1"
cmd += "[condition]=" + cb_zt.SelectedIndex.ToString()
pdtf = True
Else
cmd += " and [condition]=" + cb_zt.SelectedIndex.ToString()
'cmd += " and [condition]=1"
End If
End If
'==检测日期是否被选中
If chb_data.Checked = True Then
If pdtf = False Then
cmd += "[data]>='" + dtp_1.Value.Date.ToString() + "' and [data]<='" + dtp_2.Value.Date.ToString() + "'"
pdtf = True
Else
cmd += " and [data]>='" + dtp_1.Value.Date.ToString() + _
"' and [data]<='" + dtp_2.Value.Date.ToString() + "'"
End If
End If
selectview.sqlcmd = cmd
End If
selectview.ShowDialog()
End IfPrivate Sub selectview_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'测试窗口中传递信息是否成功
'MsgBox(sqlcmd, MsgBoxStyle.OkOnly, "提示")
'====将数据装入datagridview
Dim olecn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=固定资产.mdb")
Dim selectcmd As New OleDb.OleDbCommand()
selectcmd.Connection = olecn
Dim olead As New OleDb.OleDbDataAdapter()
olead.SelectCommand = selectcmd
olead.SelectCommand.CommandText = sqlcmd
Dim ds As New DataSet()
olead.Fill(ds)
dgv_select.DataSource = ds.Tables(0)停在了olead.fill(ds)