สวัสดี ฉันค่อนข้างใหม่กับการเขียนโปรแกรม NET ฉันต้องพัฒนาแอปพลิเคชันที่ไคลเอนต์ต้องการเข้าถึงเซิร์ฟเวอร์ผ่าน LAN และรับข้อมูลจากฐานข้อมูล MS ACCESS ระยะไกล การสื่อสารสำเร็จ และเซิร์ฟเวอร์กำลังส่งตารางข้อมูลในรูปแบบ XML ไม่ว่าเมื่อไคลเอนต์ได้รับสตริงและพยายามแปลงเป็น XML และกรอก datagridview ก็ทำให้เกิดข้อผิดพลาด
"ค่าเลขฐานสิบหก 0x00 เป็นอักขระที่ไม่ถูกต้อง"
ความช่วยเหลือในการแก้ไขปัญหานี้จะได้รับการชื่นชม ฉันใช้ทั้งการเข้ารหัส ASCII และการเข้ารหัส UTF-8 แต่ทั้งสองใช้ไม่ได้
นี่คือลูกค้าที่ส่งคำขอ
Dim client As New Net.Sockets.TcpClient
Dim stream As NetworkStream = Nothing
sql = "Select * from Roll "
client.Connect("127.0.0.1", 3000)
stream = client.GetStream
Dim sendbytes() As Byte = Encoding.ASCII.GetBytes(sql)
stream.Write(sendbytes, 0, sendbytes.Length)
จากนั้นเซิร์ฟเวอร์จะได้รับและเรียกใช้แบบสอบถามบนฐานข้อมูลและส่ง DataTable ผ่านการเชื่อมต่อ LAN
client = server.AcceptTcpClient
stream = client.GetStream
Dim rvcBytes(client.ReceiveBufferSize) As Byte
stream.Read(rvcBytes, 0, client.ReceiveBufferSize)
Dim recive As String = Encoding.ASCII.GetString(rvcBytes)
Try 'lotNumberFrom & " and LotNumber " & lotNumberTo
cmd = New OleDbCommand(recive, con)
' MsgBox(recive)
ds.Clear()
adapter.SelectCommand = cmd
adapter.Fill(ds, "Batch data")
Dim writer As New System.IO.StringWriter
ds.Tables("Batch data").WriteXml(writer, True)
' MsgBox(writer.ToString)
Dim sendbytes() As Byte = Encoding.ASCII.GetBytes(writer.ToString)
stream.Write(sendbytes, 0, sendbytes.Length)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
จากนั้นไคลเอนต์ได้รับมันและพยายามเติม datagridview นั่นคือสิ่งที่ปัญหาเกิดขึ้น
Dim rvcBytes(client.ReceiveBufferSize) As Byte
stream.Read(rvcBytes, 0, client.ReceiveBufferSize)
Dim recive As String = Encoding.ASCII.GetString(rvcBytes)
Dim dsa As New DataSet
dsa.ReadXml(New XmlTextReader(New StringReader(recive)))
DataGridView1.DataSource = dsa.Tables(0)
client.Close()