Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共3 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:利用Replace函数简化代码示例....菜鸟来学习.

1楼
菜鸟foxtable 发表于:2009/1/17 11:23:00
看看绿色代码,大家可以复制到命令窗口执行,看看如何利用Replace替换字符来简化代码.

Dim kz As String = "TextBox2,TextBox3,ComboBox1,TextBox5,TextBox6,ComboBox2,TextBox7,ComboBox3"
Dim sql As String = "UPDATE [住院登记] SET 住院号='@$10',姓名='@$11',性别='@$12',年龄='@$13',地址='@$14',费用类别='@$15',医农保证号='@$16',入院诊断='@$17' Where 住院ID = '"& Vars("str3") &"'"
dim i as integer
For Each k as string In kz.split(",")
      sql = sql.Replace("@$" & i+10,k)
      i += 1
Next
Output.Show(sql)


-------------------------------------------实例1----------------------------------------------
Dim cmd As New SQLCommand
cmd.C
With e.Form
    If .Controls("TextBox2").Value is Nothing Then
        MsgBox("住院号不能为空!",64,"提示")
    Else If .Controls("TextBox3").Value is Nothing Then
        MsgBox("姓名不能为空!",64,"提示")
    Else If .Controls("ComboBox1").Value is Nothing Then
        MsgBox("性别不能为空!",64,"提示")
    Else If .Controls("ComboBox3").Value is Nothing Then
        MsgBox("入院诊断不能为空!",64,"提示")
    Else
        Dim kz As String = "TextBox2,TextBox3,ComboBox1,TextBox5,TextBox6,ComboBox2,TextBox7,ComboBox3"
        Dim sql As String = "UPDATE [住院登记] SET 住院号='@$10',姓名='@$11',性别='@$12',年龄='@$13',地址='@$14',费用类别='@$15',医农保证号='@$16',入院诊断='@$17' Where 住院ID = '"& Vars("str3") &"'"
        dim i as integer
        For Each k as string In kz.split(",")
            sql = sql.Replace("@$" & i+10,.Controls(k).Value)
            i += 1
        Next

        cmd.CommandText = sql
        cmd.ExecuteNonQuery()
        DataTables("住院登记").Load()
        Dim dst As WinForm.DataList = e.Form.Controls("DataList1")
        cmd.CommandText = "Select 住院ID,住院号,姓名,性别,年龄,费用类别,医农保证号,入院诊断,地址 From [住院登记] Where 出院申请 = False"
        dst.DataTable = cmd.ExecuteReader()
        dst.Build()
    End If
End With
[此贴子已经被作者于2009-1-18 9:40:31编辑过]
2楼
狐狸爸爸 发表于:2009/1/18 9:09:00
建议楼主对于已经解决的问题,也不要修改标题,再后面跟一个帖子说明解决方法即可。
论坛的精髓是共享,你这样处理,就失去了这个“精髓”了。
3楼
菜鸟foxtable 发表于:2009/1/18 9:41:00
老爹,这样更改还行吧?图片点击可在新窗口打开查看
共3 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .04297 s, 2 queries.