HI i am quite new to NET programming. I had to develop an application where the client needs to access a server through a LAN, and receive data from a remote MS ACCESS database. The communication is successful and the server is sending the data table in XML format. How ever when the client receives the string and try to convert it to XML and fill a datagridview, it gives an error
"Hexadecimal value 0x00 is a invalid character"
Any help solving this would be appreciated. I used both ASCII encoding and UTF-8 encoding but both didn't work.
This is the client sending the request
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)
And then the server receives it and run the query on database and send the datatable over the LAN connection
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
Then the client recieves it and tries to fill the datagridview. Thats where the problem occurs.
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()