那么如果一个DATASET中包含图象等二进制数据,各组件间怎么用XML格式发送DATASET呢?有人告诉我XML不能表示二进制数据?

getian 2005-03-28 07:22:18
那么如果一个DATASET中包含图象等二进制数据,各组件间怎么用XML格式发送DATASET呢?有人告诉我XML不能表示二进制数据?
...全文
128 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
getian 2005-04-06
  • 打赏
  • 举报
回复
请问 GoldCodeClass 是什么类呢?我没有在MSDN,和CSDN搜索到相关的资料。
非常感谢您。
华芸智森 2005-03-29
  • 打赏
  • 举报
回复

Private MyFile As String = ""
Private MyFileExt As String = ""
Dim Conn As New SqlClient.SqlConnection
Dim BaseCtrl As New GoldCodeClass.SqlDataBaseCtrl
Dim ID As Long

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'//加载动画GIF可能会发生错误.
Dim Img As System.Drawing.Bitmap
Dim Pic As String
Dim MyXml As System.Xml.XmlDocument = New System.Xml.XmlDocument

MyXml.Load("c:\MyPhoto.xml")
Dim picNode As System.Xml.XmlNode
picNode = MyXml.SelectSingleNode("/pic/photo")
Pic = picNode.InnerText

Dim MemoryStream As System.IO.MemoryStream
MemoryStream = New System.IO.MemoryStream(Convert.FromBase64String(Pic)) '//将 BASE64 转为一个内存流
Img = New System.Drawing.Bitmap(MemoryStream) '//从内存流中建立一个图象.
Me.PictureBox1.Image = Img
MemoryStream.Close()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If MyFile = "" Then
MessageBox.Show("请选择一个图片!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End If
Dim MyImg As System.Drawing.Image = MyImg.FromFile(MyFile)
Dim memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream
MyImg.Save(memoryStream, GetImageType(MyFileExt)) '//将文件保存到内存流中.
Dim b() As Byte
b = memoryStream.GetBuffer() '//取内存流数据
Dim pic As String = Convert.ToBase64String(b) '//将数据变为 BASE64 编号
memoryStream.Close()
Dim MyXml As System.Xml.XmlDocument = New System.Xml.XmlDocument
MyXml.LoadXml("<pic><name>孟宪会</name><photo>" + pic + "</photo></pic>")
MyXml.Save("c:\MyPhoto.xml")
Label1.Text = "文件被保存到了:" + Microsoft.VisualBasic.ChrW(13) + "c:\MyPhoto.xml"
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim openFileDialog1 As New OpenFileDialog
openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "PNG(*.png)|*.png|Gif(*.gif)|*.gif|Jpg(*.jpg)|*.jpg|所有图象文件(*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = DialogResult.OK Then
MyFile = openFileDialog1.FileName()
MyFileExt = MyFile.Substring(MyFile.LastIndexOf(".") + 1)

End If
End Sub

Public Function GetImageType(ByVal str As String) As System.Drawing.Imaging.ImageFormat
Select Case str.ToLower()
Case "jpg"
Return System.Drawing.Imaging.ImageFormat.Jpeg
Case "gif"
Return System.Drawing.Imaging.ImageFormat.Gif
Case "tiff"
Return System.Drawing.Imaging.ImageFormat.Tiff()
Case "icon"
Return System.Drawing.Imaging.ImageFormat.Icon
Case "image/png"
Return System.Drawing.Imaging.ImageFormat.Png
Case "bmp"
Return System.Drawing.Imaging.ImageFormat.Bmp
Case Else
Return System.Drawing.Imaging.ImageFormat.MemoryBmp
End Select
End Function

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
'// System.Diagnostics.Process.Start("IExplore.exe", "http://xml.sz.luohuedu.net/")
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Conn = BaseCtrl.CreateSqlConn("MSTOP", "PUBS", "SA", "123")
ID = 1
End Sub

'//
'//保存图片到数据库
'//
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

If MyFile = "" Then
MessageBox.Show("请选择一个图片!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End If

Dim MyImg As System.Drawing.Image = MyImg.FromFile(MyFile)
Dim MemoryStream As System.IO.MemoryStream = New System.IO.MemoryStream
MyImg.Save(MemoryStream, GetImageType(MyFileExt)) '//将文件保存到内存流中.
'//MyImg.Save("C:\A.JPG", System.Drawing.Imaging.ImageFormat.Jpeg) '//保存为JPEG格式.
Dim B() As Byte
B = memoryStream.GetBuffer() '//取内存流数据
Dim Pic As String = Convert.ToBase64String(B) '//将数据变为 BASE64 编号
MemoryStream.Close()

Dim StrSql As String
StrSql = "DELETE FROM LXA"
BaseCtrl.ExeSqlCmd(Conn, StrSql)

StrSql = "INSERT INTO LXA (ImgID,ImgStr) VALUES('" & ID & "','" & Pic & "')"
BaseCtrl.ExeSqlCmd(Conn, StrSql)

End Sub

'//
'//从数据库中取图片.
'//
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
'//加载动画GIF可能会发生错误.
Dim Img As System.Drawing.Bitmap
Dim Pic As String
Dim StrSql As String

Pic = BaseCtrl.GetOneValue(Conn, "lxa", "ImgStr", "where ImgID='" & ID & "'")
Dim MemoryStream As System.IO.MemoryStream
MemoryStream = New System.IO.MemoryStream(Convert.FromBase64String(Pic)) '//将 BASE64 转为一个内存流
Img = New System.Drawing.Bitmap(MemoryStream) '//从内存流中建立一个图象.
Me.PictureBox1.Image = Img
MemoryStream.Close()

End Sub

End Class
华芸智森 2005-03-29
  • 打赏
  • 举报
回复

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub

'窗体重写处置以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Button6 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.Button3 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.Button4 = New System.Windows.Forms.Button
Me.Button5 = New System.Windows.Forms.Button
Me.Button6 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(438, 68)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(138, 25)
Me.Button1.TabIndex = 0
Me.Button1.Text = "将图象保存成XML"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(438, 106)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(138, 24)
Me.Button2.TabIndex = 1
Me.Button2.Text = "从XML中得到图象"
'
'PictureBox1
'
Me.PictureBox1.Location = New System.Drawing.Point(8, 24)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(408, 272)
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
Me.PictureBox1.TabIndex = 2
Me.PictureBox1.TabStop = False
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(438, 30)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(138, 25)
Me.Button3.TabIndex = 3
Me.Button3.Text = "浏览图片…"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(443, 145)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(126, 103)
Me.Label1.TabIndex = 4
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(456, 272)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(112, 32)
Me.Button4.TabIndex = 6
Me.Button4.Text = "保存到数据库"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(456, 312)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(112, 32)
Me.Button5.TabIndex = 7
Me.Button5.Text = "从数据库中取图像"
'
'Button6
'
Me.Button6.Location = New System.Drawing.Point(456, 352)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(112, 32)
Me.Button6.TabIndex = 8
Me.Button6.Text = "Button6"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(600, 516)
Me.Controls.Add(Me.Button6)
Me.Controls.Add(Me.Button5)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "图象文件和XML格式文件互换例子"
Me.ResumeLayout(False)

End Sub

#End Region
jialiang 2005-03-29
  • 打赏
  • 举报
回复
xml 可以存放二进制数据
net的最近面试经典试题ASP.NET面试题集合 1. 简述 private、 protected、 public、 internal 修饰符的访问权限。 答 . private : 私有成员, 在类的内部才可以访问。 protected : 保护成员,该类内部和继承类可以访问。 public : 公共成员,完全公开,没有访问限制。 internal: 在同一命名空内可以访问。 2 .列举ASP.NET 页面之传递值的几种方式。 答. 1.使用QueryString, 如....?id=1; response. Redirect().... 2.使用Session变量 3.使用Server.Transfer 3. 一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现。 答:public class MainClass { public static void Main() { Console.WriteLine(Foo(30)); } public static int Foo(int i) { if (i 0 && i <= 2) return 1; else return Foo(i -1) + Foo(i - 2); } } 4.C#的委托是什么?事件是不是一种委托? 答 : 委托可以把一个方法作为参数代入另一个方法。 委托可以理解为指向一个函数的引用。 是,是一种特殊的委托 5.override与重载的区别 答 : override 与重载的区别。重载是方法的名称相同。参数或参数类型不同,进行多次重载以适应不同的需要 Override 是进行基类函数的重写。为了适应需要。 6.如果在一个B/S结构的系统需要传递变量值,但是又不能使用Session、Cookie、Application,您有几种方法进行处理? 答 : this.Server.Transfer 7.请编程遍历页面上所有TextBox控件并给它赋值为string.Empty? 答: foreach (System.Windows.Forms.Control control in this.Controls) { if (control is System.Windows.Forms.TextBox) { System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control ; tb.Text = String.Empty ; } } 8.请编程实现一个冒泡排序算法? 答: int [] array = new int ; int temp = 0 ; for (int i = 0 ; i < array.Length - 1 ; i++) { for (int j = i + 1 ; j < array.Length ; j++) { if (array[j] < array) { temp = array ; array = array[j] ; array[j] = temp ; } } } 9.描述一下C#索引器的实现过程,是否只能根据数字进行索引? 答:不是。可以用任意类型。 10.求以下表达式的值,写出您想到的一种或几种实现方法: 1-2+3-4+……+m [Page] 答: int Num = this.TextBox1.Text.ToString() ; int Sum = 0 ; for (int i = 0 ; i < Num + 1 ; i++) { if((i%2) == 1) { Sum += i ; } else { Sum = Sum - I ; } } System.Console.WriteLine(Sum.ToString()); System.Console.ReadLine() ; 11.用.net做B/S结构的系统,您是用几层结构来开发,每一层之的关系以及为什么要这样分层? 答:一般为3层 数据访问层,业务层,表示层。 数据访问层对数据库进行增删查改。 业务层一般分为二层,业务表观层实现与表示层的沟通,业务规则层实现用户密码的安全等。 表示层为了与用户交互例如用户添加表单。 优点: 分工明确,条理清晰,易于调试,而且具有可扩展性。 缺点: 增加成本。 12.在下面的例子里 using Sy

16,719

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧