2013-03-11 100 views
1

這裏的1個維陣列是聲明:值不能被轉換爲字節

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類型的值不能被轉換爲字節

的1個維陣列

什麼似乎是問題?

+0

InsertClientRecord是如何定義的? – djv 2013-03-11 02:50:20

回答

1

有關錯誤好像你正試圖指定字符串Byte()

喜歡的東西:

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

這是不對的,到字符串轉換爲Byte()您需要使用Encoding

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