我在运行我的页面时遇到了错误 [英] I got the ERROR while run my page

查看:139
本文介绍了我在运行我的页面时遇到了错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友当我要运行我的页面时,我得到了



错误:无法将System.String类型的对象强制转换为System。字节[]'。像这样,请你给我一个帮助请



这里的代码



Dim TableContainer作为新的DataTable

尝试

Dim getvalues As New Select_Property()

Dim ReturnVar As Integer = 1

BusinessLayer = New BLL ()



values.FLAG =EMAIL

getsetvalues.order_No = MessageID



TableContainer = BusinessLayer.GenerateData(values,func_amc(sess_id),strUserCode,strEqyPage,)



如果TableContainer.Rows.Count> 0然后

Dim attachment As String =attachment; filename = _received.eml

Response.ContentType =application / windows live mail 2012

Response.AddHeader(Content-Disposition,附件)

Response.ClearContent()

Response.Charset =



If(Not TableContainer.Rows(0).Item(0)是DBNull.Value)然后

MailBLOB = CType(TableContainer.Rows(0).Item(0) ,Byte())

结束如果

Response.OutputStream.Read(MailBLOB,0,MailBLOB.Length)

TableContainer = Nothing

Else

ClientScript.RegisterStartupScript(Me.GetType(),Message,< script> alert('No E-mail Attached');< / script> )

结束如果

'结束如果

Catch ex1 As Threading.ThreadAbortException

抓住e作为例外

最后

BusinessLayer.Dispose()

结束尝试



Regrds,

Velsamy A

解决方案

问题出在以下代码行中



 MailBLOB = CType(TableContainer.Rows(0).Item(0),Byte())





是否有任何具体原因要转换为byte。你想用MailBLOB对象做什么我没有看到任何进一步的代码解释为什么使用MailBLOB。如果它没有用于任何特定目的,那么你可以将MailBLOB保持为字符串本身。



查看你的评论后,首先你可以使用postblob转换为字节数据getbytes方法



http://www.techrepublic.com/blog/software-engineer/convert-a-string-into-a-byte-array-in-vbnet/# [ ^ ]



这样你可以将数据保存到db。然后获取您可以在转换下方使用的数据



 字节 [ ] byteBLOBData =  new  字节 [ 0 ] ; 
byteBLOBData =( Byte [])(行[ 文档列表]);
String s = System.Text.Encoding.UTF8.GetString(byteBLOBData);


< blockquote>您好,



如果您将代码发布到卡住的地方,那将是件好事。



几乎没有类似的主题:



如何在asp.net中给出一个消息警告框? [ ^ ]



无法投射'System'类型的对象.String'键入'System.Byte []'。 [ ^ ]



无法将'System.String'类型的对象强制转换为'System.Byte []'。例外 [ ^ ]



无法将'System.String'类型的对象强制转换为'System.Byte []' [ ^ ]



http://stackoverflow.com/questions/19358883/unable-to-cast-object-of-type-system-byte-to-type-system-string [< a href =http://stackoverflow.com/questions/19358883/unable-to-cast-object-of-type-system-byte-to-type-system-stringtarget =_ blanktitle =新窗口> ^ ]



http://stackoverflow.com/questions/17769137/unable-to-cast-object-of-type -system-byte-to-type-system-string [ ^ ]


Hi Friends While i m going to run my page i am getting the

Error : Unable to cast object of type 'System.String' to type 'System.Byte[]'. like this, will you please give me a help please

code here

Dim TableContainer As New DataTable
Try
Dim getvalues As New Select_Property()
Dim ReturnVar As Integer = 1
BusinessLayer = New BLL()

values.FLAG = "EMAIL"
getsetvalues.order_No = MessageID

TableContainer = BusinessLayer.GenerateData(values, func_amc(sess_id), strUserCode, strEqyPage, "")

If TableContainer.Rows.Count > 0 Then
Dim attachment As String = "attachment; filename= _received.eml"
Response.ContentType = "application/windows live mail 2012"
Response.AddHeader("Content-Disposition", attachment)
Response.ClearContent()
Response.Charset = ""

If (Not TableContainer.Rows(0).Item(0) Is DBNull.Value) Then
MailBLOB = CType(TableContainer.Rows(0).Item(0), Byte())
End If
Response.OutputStream.Read(MailBLOB, 0, MailBLOB.Length)
TableContainer = Nothing
Else
ClientScript.RegisterStartupScript(Me.GetType(), "Message", "<script> alert('No E-mail Attached');</script>")
End If
'End If
Catch ex1 As Threading.ThreadAbortException
Catch e As Exception
Finally
BusinessLayer.Dispose()
End Try

Regrds ,
Velsamy A

解决方案

The problem is in below line of code

MailBLOB = CType(TableContainer.Rows(0).Item(0), Byte())



Is there any specific reason why you are converting to byte. What are you trying to do with MailBLOB object. I do not see any further code which explains why MailBLOB is used. If it is not used for any specific purpose then you can keep MailBLOB as string itself.

After looking at your comments, first you can convert the mailblob to byte data using getbytes method

http://www.techrepublic.com/blog/software-engineer/convert-a-string-into-a-byte-array-in-vbnet/#.[^]

This way you can save data to db. Then to fetch the data you can use below conversion

Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(row["DOCLIST"]);
String s = System.Text.Encoding.UTF8.GetString(byteBLOBData);


Hi,

It would be good if you post your code where you got stuck.

There are few similar thread:

how to give a message alert box in asp.net ?[^]

Unable to cast object of type 'System.String' to type 'System.Byte[]'.[^]

Unable to cast object of type 'System.String' to type 'System.Byte[]'. Exception[^]

Unable to cast object of type 'System.String' to type 'System.Byte[]'[^]

http://stackoverflow.com/questions/19358883/unable-to-cast-object-of-type-system-byte-to-type-system-string[^]

http://stackoverflow.com/questions/17769137/unable-to-cast-object-of-type-system-byte-to-type-system-string[^]


这篇关于我在运行我的页面时遇到了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆