如何在VB.NET中的字符串中存储文本框值 [英] How to Store Textbox value in String in VB.NET

查看:187
本文介绍了如何在VB.NET中的字符串中存储文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个textBox
用户输入值1并将其保存在数据库中.
当用户保存值"时,表单不会关闭.
下一个用户输入值2并再次保存.
这一次在保存需求的同时,它应该保存上一个
值也表示1.再次,当用户输入3并保存时,然后保存
它应该将1,2,3保存到数据库中.我该怎么办.
如何将这些值存储在字符串中.直到关闭窗体.
能做完吗?
请协助

I have a textBox
user enter values 1 and saves it in database.
when user saves the Value the form is not getting closed.
Next user enter value 2 and again saves it.
This time while saving the need is that it should save the Previous
value also means 1. Again when user enters 3 and saves this then .while saving
it should save 1,2,3 in database.How can I do this .
How to store these values in a string .until the Form is closed.
Can this be Done .
Please assist
How to do this.

推荐答案

我不确定您要达到的目标,但在我看来,您可以使用数组或字符串列表来存储值.
I am not exactly sure what you are trying to achive but seems to me you could use an array or a list of strings to store the values.


从您的详细信息看来,您似乎想在数据库中有一列要使用用户输入的ID(用逗号分隔)填充.

在这一点上,您的设计似乎效率不高.不要用逗号分隔ID,而应创建一个与现有表具有Master/Child关系的单独表.所以代替这个:

假设
--------------------
表A(您的方式)
--------------------
自动识别| ID
1 | 1,2
2 | 1,2,4
3 | 3,4,7

应该是:

--------------------
表主(我的建议)
--------------------
自动识别| ID
1 | 1< ---------"Table child"的"AutoID"
2 | 2< ---------"Table child"的"AutoID"
3 | 3< ---------"Table child"的"AutoID"

--------------------
表子
--------------------
自动识别| ID
1 | 1
1 | 2
2 | 1
2 | 2
2 | 4
3 | 3
3 | 4
3 | 7

它有助于管理数据并使它们易于操作.

如果您无法更改表结构,则需要通过在最后附加用户提供的ID来更新数据,如下所示:(假设将SQL作为后端)

From your details it looks like you have a column in database which you want to populate with the IDs (comma separated) entered by user.

At this point, your design does not seems to be much efficient. Rather than getting comma separated IDs you should create a separate table with Master/Child relationship to the existing one. So Instead of this:

Suppose,
--------------------
Table A (Your way)
--------------------
AutoID | IDs
1 | 1,2
2 | 1,2,4
3 | 3,4,7

It should be:

--------------------
Table Master (My Recommendation)
--------------------
AutoID | IDs
1 | 1 <--------- "AutoID" of "Table child"
2 | 2 <--------- "AutoID" of "Table child"
3 | 3 <--------- "AutoID" of "Table child"

--------------------
Table Child
--------------------
AutoID | IDs
1 | 1
1 | 2
2 | 1
2 | 2
2 | 4
3 | 3
3 | 4
3 | 7

It helps to manage data and make them easy to manipulate.

In case you can not change table structure, you need to update data by appending ID provided by user at the end, something like this: (Assuming SQL as backend)

update TableA set [Ids] = [Ids] + ',' + UserProvidedId 
WHERE <condition>



因此,如果列[Ids]的第一行具有"1,2",并且用户输入3,则update语句将其变为"1,2,3".

现在,您可以看到在这种逗号分隔的设计中,如果不执行SPLIT或SUBSTRING很难找到重复项.



So if first row of column [Ids] has ''1,2'' and users entered 3 then update statement will make it ''1,2,3''.

Now you can see in this comma seperated design it is hard to find duplicates without doing a SPLIT or SUBSTRING.


这篇关于如何在VB.NET中的字符串中存储文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆