用VB写的,将数据库中的数据导出到Excel中,但导出后汉字部分出现了乱码。不知是怎么回事,请各位帮帮忙!代码如下:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim adapter As New SqlDataAdapter
Dim MyConnection As New SqlConnection
Dim Myselectcommand As New System.Data.SqlClient.SqlCommand
MyConnection.ConnectionString = "data source=work6;Initial catalog=CRMData-test;User ID=sa;Password=123"
Myselectcommand.CommandText = "select * from log"
Myselectcommand.CommandType = CommandType.Text
Myselectcommand.Connection = MyConnection adapter.SelectCommand = Myselectcommand
Dim dtable As DataTable
dtable = New DataTable
adapter.Fill(dtable)
Response.ContentType = "application/ms-Excel" Response.AddHeader("Content-Disposition", "inline;filename=log_backup.xls")
End SubPrivate Function ConvertDtToTDF(ByVal dt As DataTable) As String
Dim dr As DataRow, ary() As Object, i As Integer
Dim iCol As Integer
For iCol = 0 To dt.Columns.Count - 1
Response.Write(dt.Columns(iCol).ToString & vbTab)
Next
Response.Write(vbCrLf)
For Each dr In dt.Rows
ary = dr.ItemArray
For i = 0 To UBound(ary)
Response.Write(ary(i).ToString & vbTab)
Next
Response.Write(vbCrLf)
Next
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim adapter As New SqlDataAdapter
Dim MyConnection As New SqlConnection
Dim Myselectcommand As New System.Data.SqlClient.SqlCommand
MyConnection.ConnectionString = "data source=work6;Initial catalog=CRMData-test;User ID=sa;Password=123"
Myselectcommand.CommandText = "select * from log"
Myselectcommand.CommandType = CommandType.Text
Myselectcommand.Connection = MyConnection adapter.SelectCommand = Myselectcommand
Dim dtable As DataTable
dtable = New DataTable
adapter.Fill(dtable)
Response.ContentType = "application/ms-Excel" Response.AddHeader("Content-Disposition", "inline;filename=log_backup.xls")
End SubPrivate Function ConvertDtToTDF(ByVal dt As DataTable) As String
Dim dr As DataRow, ary() As Object, i As Integer
Dim iCol As Integer
For iCol = 0 To dt.Columns.Count - 1
Response.Write(dt.Columns(iCol).ToString & vbTab)
Next
Response.Write(vbCrLf)
For Each dr In dt.Rows
ary = dr.ItemArray
For i = 0 To UBound(ary)
Response.Write(ary(i).ToString & vbTab)
Next
Response.Write(vbCrLf)
Next
End Function
解决方案 »
- 关于 this.ClientScript.RegisterOnSubmitStatement()的问题
- C# 中 Ref 相当于js中?
- 仿贵论坛csdn首页定义框架 点击帖子不能弹出新页面
- 谁能给我一个coderush for .net 2.5 版本以上的安装程序和crack ,100全给你.
- 想利用HttpWebRequest获取转址后的对方URL信息,请大家进来参与下。
- webform中的treeview
- 可怪的 应用程错误“未能加载类型”
- 用FindControl调用子控件报错!
- 为什么js文件中有中文时,使用就会出现错误?如何解决或者避免?
- 用VS.net开发网站的具体步骤是什么?
- 如何在网页中嵌入VB.NET 做的windows 应用程序?
- 因被攻击,现将SQL Server1433端口修改了,数据库不能使用,怎么办?
<?xml version="1.0" encoding="gb2312" ?>之后在<system.web>节中增加<globalization
requestEncoding="gb2312"
responseEncoding="gb2312"
/>
问题解决。谢谢LoveCherry(论成败,人生豪迈;大不了,重头再来!^_^)!谢谢诸位!