【问题标题】:Value of type String cannot be converted to 1 dimensional array of ByteString 类型的值不能转换为 Byte 的一维数组
【发布时间】:2013-03-11 01:49:44
【问题描述】:

声明如下:

Public Class Client
Public Property Address() As String
    Get
        Return mAddress

    End Get
    Set(ByVal value As String)
        mAddress = value
    End Set
End Property
Public Property City() As String
    Get
        Return mCity

    End Get
    Set(ByVal value As String)
        mCity = value
    End Set
End Property
end sub

错误就在这里:

Public Function InsertClientRecordToDb(ByVal cli As Client) As Boolean
        Dim retVal As Boolean
        Dim dataSet As DataSet = New DataSet("dataSet")
        dataSet.EnforceConstraints = False
        'create table adapter object
        Dim ClientTblAdapter As New CaseStudyDBDataSetTableAdapters.Client_TableTableAdapter

    'check db connection
    If ClientTblAdapter.Connection.State = ConnectionState.Closed Then
        ClientTblAdapter.Connection.Open()
    End If

    'perform(insert)
    If ClientTblAdapter.InsertClientRecord(cli.Clientcode, cli.Clientname, cli.Address, cli.City, cli.Contactperson, cli.Contactnumber) > 0 Then
        retVal = True
    End If**

    Return retVal
End Function

“cli.Address”和“cli.City”下划线表示:

String类型的值不能转换为Byte的一维数组

似乎是什么问题?

【问题讨论】:

  • InsertClientRecord 是如何定义的?

标签: vb.net tableadapter


【解决方案1】:

对于错误,您似乎正在尝试将字符串分配给Byte()

类似:

Dim bArr As Byte() = "hello world!"

这是错误的,要将字符串转换为Byte() 您需要使用Encoding

Dim bArr As Byte() = System.Text.Encoding.Default.GetBytes("hello world!")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多