如何在一个字段中加分隔符分开数据?

rainwangbest 2003-09-12 11:36:11
现有四个文本框,输入数据后将四个文本框中的数据存入数据库中一个字段下。数据间用分隔符分开。如果第二个文本框为空,则该字段只有一个数据就不必用分隔符分开。如果第三个文本框为空,则该字段只有一个分隔符将一、二数据分隔。如果第四个文本框为为空,则该字段只有两个分隔符将一、二、三数据分隔。
例如:text1是1,text2是2,text3是3,text4是4,则存入数据库字段a中应是
"1;2;3;4"。如果text2为空,则字段a应是"1"。不知如何用代码实现,并且如何读取字段a,将数据分别对应在四个文本框中?谢谢
...全文
169 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yijiansong 2003-09-12
  • 打赏
  • 举报
回复
Dim str As String

Private Sub Command1_Click()
str=vbnullstring
if trim(Text1.Text)<>"" then
str=str & trim(Text1.Text)
end if

if trim(Text2.Text)<>"" then
str=str & ";" & trim(Text2.Text)
end if

if trim(Text3.Text)<>"" then
str=str & ";" & trim(Text3.Text)
end if

if trim(Text4.Text)<>"" then
str=str & ";" & trim(Text4.Text)
end if



MsgBox str
'存入数据库
End Sub

Private Sub Command2_Click()
Dim strTmp() As String
'从数据库中得到str
strTmp = Split(str, ";")
Text1.Text = strTmp(0)
Text2.Text = strTmp(1)
Text3.Text = strTmp(2)
Text4.Text = strTmp(3)
End Sub

lihonggen0 2003-09-12
  • 打赏
  • 举报
回复
Dim str As String

Private Sub Command1_Click()
str = Text1.Text & ";" & Text2.Text & ";" & Text3.Text & ";" & Text4.Text & ";"
MsgBox str
'存入数据库
End Sub

Private Sub Command2_Click()
Dim strTmp() As String
'从数据库中得到str
strTmp = Split(str, ";")
Text1.Text = strTmp(0)
Text2.Text = strTmp(1)
Text3.Text = strTmp(2)
Text4.Text = strTmp(3)
End Sub
lihonggen0 2003-09-12
  • 打赏
  • 举报
回复
Dim str As String

Private Sub Command1_Click()
str = Text1.Text & ";" & Text2.Text & ";" & Text3.Text & ";" & Text4.Text & ";"
MsgBox str
'存入数据库
End Sub

Private Sub Command2_Click()
Dim strTmp() As String
'从数据库中得到str
strTmp = Split(str, ";")
Text1.Text = strTmp(0)
Text2.Text = strTmp(1)
Text3.Text = strTmp(2)
Text4.Text = strTmp(3)
End Sub
dddd8888 2003-09-12
  • 打赏
  • 举报
回复
select case

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧