看看绿色代码,大家可以复制到命令窗口执行,看看如何利用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编辑过]
建议楼主对于已经解决的问题,也不要修改标题,再后面跟一个帖子说明解决方法即可。
论坛的精髓是共享,你这样处理,就失去了这个“精髓”了。