修改Label的Text值时遇到奇怪问题
我做了一个导出数据库的小程序,有一个label,一个Dropdownlist,一个Botton,我想实现点击导出时让Label显示提示信息,如“正在导出,请稍候..”,当程序快执行完时label显示"导出完成"。
代码如下:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim EquipmentName As String
Dim cmdString1 As String
Label1.Text="正在导出,请稍候..."
Label1.CssClass="red"
EquipmentName = DropDownList1.SelectedValue
If EquipmentName = "" Then
cmdString1 = "Select * from equipment"
GetData(cmdString1)
Else
cmdString1 = "select * from equipment where E_name ='" & EquipmentName & "'"
GetData(cmdString1)
End If
End Sub
GetData是个函数 代码如下:
Sub GetData(ByVal cmdString As String)
Dim conn As SqlConnection
Dim MyDataAdpter As SqlDataAdapter
Dim MyDataSet As DataSet
conn = New SqlConnection(ConfigurationManager.ConnectionStrings("Shenzhou").ConnectionString)
MyDataAdpter = New SqlDataAdapter(cmdString, conn)
conn.Open()
MyDataSet = New DataSet
MyDataAdpter.Fill(MyDataSet, "Equipment")
Dim xlApp As Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim x As Integer 'Excel中的行
Dim y As Integer 'Excel中的列
Dim i As Integer '数据库中的行
Dim k As Integer '数据库中的列
Dim id As Integer 'id
x = 1
y = 1
id = 1
xlApp = CreateObject(" Excel.Application") '实例化对象
xlWorkbook = xlApp.Workbooks.Add() '创建一个新的workbook
xlWorkSheet = xlWorkbook.Worksheets("sheet1") '创建一个新的worksheet
'创建EXCEL 表头
xlWorkSheet.Cells(x, y) = "设备清单"
With xlWorkSheet
.Range(.Cells(x, y), .Cells(x, y)).Font.Size = 16
.Range(.Cells(x, y), .Cells(x, y)).Font.Name = "黑体"
End With
xlWorkSheet.Cells(x + 2, y) = "序号"
xlWorkSheet.Cells(x + 2, y + 1) = "设备名称"
xlWorkSheet.Cells(x + 2, y + 2) = "设备品牌"
xlWorkSheet.Cells(x + 2, y + 3) = "设备型号"
xlWorkSheet.Cells(x + 2, y + 4) = "计算机类型"
xlWorkSheet.Cells(x + 2, y + 5) = "设备出厂编号"
xlWorkSheet.Cells(x + 2, y + 6) = "设备编号"
xlWorkSheet.Cells(x + 2, y + 7) = "设备统一编号"
xlWorkSheet.Cells(x + 2, y + 8) = "使用人"
xlWorkSheet.Cells(x + 2, y + 9) = "设备状态"
xlWorkSheet.Cells(x + 2, y + 10) = "放置房间"
xlWorkSheet.Cells(x + 2, y + 11) = "具体位置"
xlWorkSheet.Cells(x + 2, y + 12) = "购买类型"
xlWorkSheet.Cells(x + 2, y + 13) = "入帐日期"
xlWorkSheet.Cells(x + 2, y + 14) = "操作系统安装时间"
xlWorkSheet.Cells(x + 2, y + 15) = "硬盘序列号"
xlWorkSheet.Cells(x + 2, y + 16) = "IP地址"
xlWorkSheet.Cells(x + 2, y + 17) = "MAC地址"
xlWorkSheet.Cells(x + 2, y + 18) = "备注"
'导出数据开始
For x = 0 To (MyDataSet.Tables("Equipment").Rows.Count - 1)
xlWorkSheet.Cells(x + 4, y) = id
id = id + 1
xlWorkSheet.Cells(x + 4, y + 1) = MyDataSet.Tables("Equipment").Rows(x)(1) '设备名称
xlWorkSheet.Cells(x + 4, y + 2) = MyDataSet.Tables("Equipment").Rows(x)(2) '品牌
xlWorkSheet.Cells(x + 4, y + 3) = MyDataSet.Tables("Equipment").Rows(x)(3) '型号
xlWorkSheet.Cells(x + 4, y + 4) = MyDataSet.Tables("Equipment").Rows(x)(12) '类型
xlWorkSheet.Cells(x + 4, y + 5) = MyDataSet.Tables("Equipment").Rows(x)(4) '出厂编号
xlWorkSheet.Cells(x + 4, y + 6) = MyDataSet.Tables("Equipment").Rows(x)(5) '设备编号
xlWorkSheet.Cells(x + 4, y + 7) = MyDataSet.Tables("Equipment").Rows(x)(6) '统一编号
xlWorkSheet.Cells(x + 4, y + 8) = MyDataSet.Tables("Equipment").Rows(x)(7) '使用人
xlWorkSheet.Cells(x + 4, y + 9) = MyDataSet.Tables("Equipment").Rows(x)(8) '状态
xlWorkSheet.Cells(x + 4, y + 10) = MyDataSet.Tables("Equipment").Rows(x)(9) '房间号
xlWorkSheet.Cells(x + 4, y + 11) = MyDataSet.Tables("Equipment").Rows(x)(14) '位置
xlWorkSheet.Cells(x + 4, y + 12) = MyDataSet.Tables("Equipment").Rows(x)(10) '购买类型
xlWorkSheet.Cells(x + 4, y + 13) = MyDataSet.Tables("Equipment").Rows(x)(11) '日期
xlWorkSheet.Cells(x + 4, y + 14) = MyDataSet.Tables("Equipment").Rows(x)(15) '操作系统安装时间
xlWorkSheet.Cells(x + 4, y + 15) = MyDataSet.Tables("Equipment").Rows(x)(16) '硬盘序列号
xlWorkSheet.Cells(x + 4, y + 16) = MyDataSet.Tables("Equipment").Rows(x)(17) 'IP地址
xlWorkSheet.Cells(x + 4, y + 17) = MyDataSet.Tables("Equipment").Rows(x)(18) 'MAC地址
xlWorkSheet.Cells(x + 4, y + 18) = MyDataSet.Tables("Equipment").Rows(x)(13) '备注
Next
xlApp.Visible = True
Label1.Text="导出完成"
Label1.CssClass="red"
End Sub
可是问题出来了,当我点击的时候,Label的text就是没反应,我又试了好多遍还是没反应,最后把Button1_Click事件里的代码都删掉,只留下Label1.Text="正在导出,请稍候.."。 这下可以了!
后来研究了半天也没明白,请高手赐教!