Foxtable(狐表)用户栏目专家坐堂 → 返回指定格式的string


  共有2049人关注过本帖树形打印复制链接

主题:返回指定格式的string

帅哥哟,离线,有人找我吗?
huhu
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1165 积分:8129 威望:0 精华:0 注册:2015/3/30 10:44:00
返回指定格式的string  发帖心情 Post By:2016/11/18 17:58:00 [只看该作者]

Public Function GetState1(ByVal ddh As String, ByVal ddhh As String, ByVal wlbm As String, ByVal lhbbh As String, ByVal rjbb As String) As String
        Dim cnStr As String = "Data Source=(local);Initial Catalog=songjiang;Integrated Security=False;User ID=sa;Password=bdcom103liujy;"
        Dim cn As New SqlClient.SqlConnection(cnStr)
        cn.Open()
        Dim cm As New SqlClient.SqlCommand("s elect 数量 from [可用数量表]  where 订单号 = '" & ddh & "' and 订单行号 = '" & ddhh & "' and 物料编码 = '" & wlbm & "' and 两化表编号 = '" & lhbbh & "' and 软件版本 = '" & rjbb & "'", cn)
        Dim state As String = cm.ExecuteScalar
        cn.Close()
        Return state
    End Function

现在返回的就是一个数量值。
假如有A,B,C,数量4个列他们只为1,2,3,4
希望返回的格式为A:1,B:2,C:3,D:4
这种格式怎么弄?

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107456 积分:546559 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/11/18 18:06:00 [只看该作者]

Dim cm As New SqlClient.SqlCommand("s elect 'A:'+ cast([A] as nvarchar) + ',B:'+ cast([B] as nvarchar) + ...... from [可用数量表]  where 订单号 = '" & ddh & "' and 订单行号 = '" & ddhh & "' and 物料编码 = '" & wlbm & "' and 两化表编号 = '" & lhbbh & "' and 软件版本 = '" & rjbb & "'", cn)

 回到顶部
帅哥哟,离线,有人找我吗?
有点青
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:573 积分:2961 威望:0 精华:0 注册:2016/10/27 14:33:00
  发帖心情 Post By:2016/11/18 18:09:00 [只看该作者]

 和foxtable一样,你直接查询到表,然后循环每一行,合并成你想要的数据啊。

 回到顶部
帅哥哟,离线,有人找我吗?
huhu
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1165 积分:8129 威望:0 精华:0 注册:2015/3/30 10:44:00
  发帖心情 Post By:2016/11/18 18:31:00 [只看该作者]

可明明有2行数据,却只返回第一行是怎么回事?
<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="WebApplication4">生产订单号码:SC20160922001,工单行号:26,数量:15</string>

 回到顶部
帅哥,在线噢!
有点蓝
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107456 积分:546559 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/11/19 8:39:00 [只看该作者]

Public Function GetState1(ByVal ddh As String, ByVal ddhh As String, ByVal wlbm As String, ByVal lhbbh As String, ByVal rjbb As String) As String
Dim cnStr As String = "Data Source=(local);Initial Catalog=songjiang;Integrated Security=False;User ID=sa;Password=bdcom103liujy;"
Dim cn As New SqlClient.SqlConnection(cnStr)
cn.Open()
Dim cm As New SqlClient.SqlCommand("s elect * from [可用数量表]  where 订单号 = '" & ddh & "' and 订单行号 = '" & ddhh & "' and 物料编码 = '" & wlbm & "' and 两化表编号 = '" & lhbbh & "' and 软件版本 = '" & rjbb & "'", cn)
Dim dt As DataTable = cm.ExecuteReader
cn.Close()
Dim state As String
For Each dr As DataRow In dr.DataRow
    '拼接每行的数据
Next
Return state
End Function

 回到顶部
帅哥哟,离线,有人找我吗?
huhu
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1165 积分:8129 威望:0 精华:0 注册:2015/3/30 10:44:00
  发帖心情 Post By:2016/11/28 10:07:00 [只看该作者]

Public Function GetState1(ByVal ddh As String, ByVal ddhh As String, ByVal wlbm As String, ByVal lhbbh As String, ByVal rjbb As String) As String
        Dim cnStr As String = "Data Source=(local);Initial Catalog=songjiang;Integrated Security=False;User ID=sa;Password=bdcom103liujy;"
        Dim cn As New SqlClient.SqlConnection(cnStr)
        cn.Open()
        Dim cm As New SqlClient.SqlCommand("s elect * from [可用数量表]  where 订单号 = '" & ddh & "' and 订单行号 = '" & ddhh & "' and 物料编码 = '" & wlbm & "' and 两化表编号 = '" & lhbbh & "' and 软件版本 = '" & rjbb & "'", cn)
        Dim dt As DataTable = cm.ExecuteReader
        cn.Close()
        Dim state As String
        For Each dr As DataRow In dt.datarow
            state + = '工单号:' + dr("工单号") + ',工单行号:' + dr("工单行号") + ",物料编码:" + dr("物料编码") + ",数量:" + dr("数量")
        Next
        Return state
    End Function

图片点击可在新窗口打开查看此主题相关图片如下:error1.png
图片点击可在新窗口打开查看



 回到顶部
帅哥,在线噢!
有点蓝
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107456 积分:546559 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/11/28 10:19:00 [只看该作者]

vs的用法和foxtable不一样,找书或者上网先学学基本的用法

https://www.baidu.com/baidu?tn=02049043_69_pg&ie=utf-8&word=SqlDataAdapter

https://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqldataadapter(VS.80).aspx

http://blog.sina.com.cn/s/blog_5c52ae1b0100q4uj.html

 回到顶部
帅哥哟,离线,有人找我吗?
huhu
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1165 积分:8129 威望:0 精华:0 注册:2015/3/30 10:44:00
  发帖心情 Post By:2016/11/28 10:24:00 [只看该作者]

能先帮我改一下吗?

 回到顶部
帅哥,在线噢!
有点蓝
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107456 积分:546559 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/11/28 10:39:00 [只看该作者]

    Public Function GetState1(ByVal ddh As String, ByVal ddhh As String, ByVal wlbm As String, ByVal lhbbh As String, ByVal rjbb As String) As String
        Dim cnStr As String = "Data Source=(local);Initial Catalog=songjiang;Integrated Security=False;User ID=sa;Password=bdcom103liujy;"
        Dim cn As New SqlClient.SqlConnection(cnStr)
        cn.Open()
        Dim adapter As New SqlClient.SqlDataAdapter("select * from [可用数量表]  where 订单号 = '" & ddh & "' and 订单行号 = '" & ddhh & "' and 物料编码 = '" & wlbm & "' and 两化表编号 = '" & lhbbh & "' and 软件版本 = '" & rjbb & "'", cn)

        Dim dt As New DataTable
        adapter.Fill(dt)
        cn.Close()
        Dim state As String = ""
        For Each dr As DataRow In dt.Rows
            state += "工单号:" + dr("工单号") + ",工单行号:" + dr("工单行号") + ",物料编码:" + dr("物料编码") + ",数量:" + dr("数量")
        Next
        Return state
    End Function

 回到顶部
帅哥哟,离线,有人找我吗?
huhu
  10楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1165 积分:8129 威望:0 精华:0 注册:2015/3/30 10:44:00
  发帖心情 Post By:2016/11/28 11:22:00 [只看该作者]

输入参数后提示下面的:

网站无法显示该页面

 HTTP 500
 

最可能的原因是:

  • 该网站正在进行维护。
  • 该网站有程序错误。
 

你可以尝试以下操作:

 

图片点击可在新窗口打开查看 刷新该页面。

 

图片点击可在新窗口打开查看 返回到上一页。

 

图片点击可在新窗口打开查看 详细信息

另外多行要分行显示出来。用vbcrif?
state += "工单号:" + dr("工单号") + ",工单行号:" + dr("工单行号") + ",物料编码:" + dr("物料编码") + ",数量:" + dr("数量")

 回到顶部
总数 13 1 2 下一页