douyi8732 2015-03-08 08:44
浏览 192
已采纳

从vb.Net向服务器上的PHP发送数据数组

I don't know if this is even possible, and I can't figure how to achieve this.

I have 50 (can be more) records in MS Access database that I wish to send to a a php file at my server for further processing.

What I have implemented so far is that I loop through the records and send them one by one. This kind of takes time cause of network issues, some records will be sent and others won't and each data sent will have to wait for report from server before the next one will be sent.

Is there a way I can send all records once, maybe in an array or something and be able to access it at the server side?

Below is my table schema.

--------------------------
|  id  |  phone  |  msg  |
--------------------------
|  1   | 09023023|  hi   |
|  2   | 09023024|  hey  |
|  3   | 09023025|  dear |  
--------------------------

Thanks

  • 写回答

2条回答 默认 最新

  • douchuose2514 2015-04-15 10:37
    关注

    I found a solution for this. I don't know if it is the best way out there but it worked well.

    On @Tushar Gupta suggestion, I created a Json Array using a third party Json Library found at http://www.newtonsoft.com/

    I looped through the data in the database and concatenated them like so:

    CODE

        Dim sms As New Sms 'note that this is a class
        Dim sms_obj As String = ""
    
    
        Try
            conn.Open()
    
            Dim cmd As OleDbCommand = New OleDbCommand("id, phone, msg FROM sms;", conn)
    
            Dim reader As OleDbDataReader = cmd.ExecuteReader
    
    
            'collate sms
            Dim i As Integer = 0
            While reader.Read()
    
                sms.id = reader("id").ToString()
                sms.member_phone = reader("phone").ToString()
                sms.member_message = reader("msg").ToString()
    
    
                If sms_obj = "" Then
                    sms_obj = sms_obj + JsonConvert.SerializeObject(sms, Formatting.Indented)
                Else
                    sms_obj = sms_obj + "," + JsonConvert.SerializeObject(sms, Formatting.Indented)
                End If
    
            End While
    
            sms_obj = "{ ""sms""" + ":" + "[" + sms_obj + "]}" ' this put the json string in an array
    
            'close the connection
            conn.Close()
    
    
            If sms.ToString <> "" Then
                HelperModule.SendSms(sms_obj)
            End If
    
    
            lblSmsState.Text = "sending sms done!"
    
        Catch ex As Exception
            msgbox(ex.toString())
            conn.Close()
        End Try
    

    OUTPUT

        { "sms":[
              {
                "id": "1",
                "member_phone": "09023023",
                "member_message": "hi"
              },{
                "id": "2",
                "member_phone": "09023024",
                "member_message": "hey"
              },{
                "id": "3",
                "member-phone": "09023025",
                "member_message": "dear"
              }
    
            ]
          }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 脱敏项目合作,ner需求合作
  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴