从文本框拆分的单词和值在数据库中传递 [英] word split from textbox and values pass in database
本文介绍了从文本框拆分的单词和值在数据库中传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i想从文本框中拆分单词,
表示..按名字或姓氏搜索用户
。
和我的传递文本框值的编码为firstname,属性中的lastname在这里..
它告诉我错误如果我离开了空间
意味着
i enterd
manish dalwadi
in textbox
完整的工作
但如果我只输入了
manish它给我看错误
i wan to split words from textbox,
means..i search users by firstname or lastname
.
and my coding for pass textbox valu as firstname , lastname in property is here..
it show me error if i left the space
means
i enterd
manish dalwadi
in textbox
its complete work
but if i entered only
manish it show me error
string data = txtsearchusers.Text;
string[] s1 = data.Split();
string a = s1[0].ToString();
string b = s1[1].ToString();
clsregisterinfo.FirstName = a.ToString();
clsregisterinfo.LastName = b.ToString();
推荐答案
检查条件并指定b值;
Check th econdition and assign b value;
if (s1 != null && s1.Count() > 1)
{
string b = s1[1].ToString();
clsregisterinfo.LastName = b.ToString();
}
为什么要拆分文本框值。如果你想搜索用户意味着你可以在sql查询它自己做。喜欢
Hi,
Why you are splitting the text box value.If u want to search users means u can do it in sql query it self. like
string search = "select * from tblUsers where name like'%" + txtUsername.Text + "'%";
然后绑定您想要显示的值。
Then bind the value where ever u want to show.
你会遇到IndexOutofRangeException,对吗?那是因为s1 [1]不存在。
建议使用2个文本框,一个用于名字,另一个用于姓氏。它不仅消除了不必要的代码,而且还使用户的意图更加清晰。
You would have encountered IndexOutofRangeException, right? That is because s1[1] did not exist.
Suggest use 2 textboxes, one for firstname and another for last name. Not only does it eliminate unnecessary code, but also make your intention clearer to the users as well.
这篇关于从文本框拆分的单词和值在数据库中传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文