如何在两个文本框的两个字符串之间添加空格? [英] How to add space between two string of two text-boxes ?

查看:732
本文介绍了如何在两个文本框的两个字符串之间添加空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我有两个文本框,一个用于firstname,另一个用于lastname。当我将它存储到数据库中时,它看起来像firstnamelastname但我需要它们之间的空格,如(firstname lastname)。那么它怎么可能和我必须做什么?



谢谢,

Hello,
I have two text-boxes, one for firstname and other for lastname. When I store it into database, it looks like firstnamelastname but I need space in between them like (firstname lastname). So how it can be possible and what I have to do ?

Thanks,

推荐答案

hey priyanka ...



只需将两个文本框的值存储在一个字符串变量中,并将该变量传递给sql查询。


例如,




string fullName = txtFirstName.Text ++ txtLastName.Text;



现在将此变量传递给sql查询



for ex,



插入tblName值(fullName);



gud luck
hey priyanka...

simply store the values of both textboxes in a string variable and pass that variable to sql query.

for example,

string fullName = txtFirstName.Text + " " + txtLastName.Text;

and now pass this variable to sql query

for ex,

insert into tblName values (fullName);

gud luck


不要。

如果您在分隔的字段,将它们存储在单独的字段中。

否则,你丢弃信息,并对信息做出假设!



存储它们在单独的字段中,您可以检索友好问候的名字:

Don't.
If you get information in separated fields, store them in separated fields.
Otherwise, you are throwing information away, and making assumptions about the information!

Store them in separate fields, and you can retrieve the "first name" for friendly greetings:
string greet = "Hi " + firstName;

或添加敬语:

Or add an honorific:

string greet = "Dear Mr " + lastName;



您可以随时从数据库中检索全名:


You can retrieve the "full name" from the DB at any time:

SELECT FirstName + ' ' + LastName AS [Full Name] FROM MyTable


使用如下



use like below

string Name = txtFirstName.Text.Trim() + " " + txtLastName.Text.Trim();





您只需使用变量名称并将其传递到数据库。





谢谢,

-RG



you just use variable Name and pass it into database.


Thanks,
-RG


这篇关于如何在两个文本框的两个字符串之间添加空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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