如何组合两个字段以适合表单上的一个字段 [英] How do I combine 2 fields to fit into one on a form

查看:95
本文介绍了如何组合两个字段以适合表单上的一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 SqlConnection connect = new SqlConnection(); 
connect.ConnectionString = ConfigurationManager.ConnectionStrings [WEBHR]。ConnectionString;
connect.Open();
SqlDataAdapter da = new SqlDataAdapter(select * from transfer order by empno,connect);

DataSet ds = new DataSet();
da.Fill(ds,转移);

txt_Empno.Text = ds.Tables [Transfer]。行[0] [EMPNO]。ToString();
txt_Name.Text = ds.Tables [Transfer]。行[0] [FNAME]。ToString();









请求

 txt_Name.Text 

是'FNAME'+''+'LNAME'



如何组合2个字段



请协助



我的尝试:



以上是我的搜索中没有示例的问题

解决方案

对于首发,请不要使用 SELECT * FROM ... - 列出您希望返回的列是一个更好的主意,因为它将来会证明您的应用程序,并且不会浪费您不会使用的数据带宽。



如果你这样做,你可以在SQL中组合字段:

  SELECT  EmpNo,FName + ' ' + LName  AS  [名称]  FROM 传输 ORDER   BY  EmpNo 


通过 OriginalGriff [ ^ ],这是另一种方式:

 DataRow dr = ds.Tables [ 传输​​]。行[ 0 ]; 
txt_Name.Text = string .Concat(dr [ FNAME]。ToString()。Trim(), , dr [ LNAME]。ToString()。Trim());


SqlConnection connect = new SqlConnection();
               connect.ConnectionString = ConfigurationManager.ConnectionStrings["WEBHR"].ConnectionString;
               connect.Open();
               SqlDataAdapter da = new SqlDataAdapter("select * from Transfer order by empno", connect);

               DataSet ds = new DataSet();
               da.Fill(ds, "Transfer");

               txt_Empno.Text             = ds.Tables["Transfer"].Rows[0]["EMPNO"].ToString();
               txt_Name.Text              = ds.Tables["Transfer"].Rows[0]["FNAME"].ToString();





The request is

txt_Name.Text 

is 'FNAME'+' '+'LNAME'

How do you combine 2 fields

Please assist

What I have tried:

The above is the issue no example from my search

解决方案

For starter, don't use SELECT * FROM ... - it's a much better idea to list the columns you wish to return as it future proofs your app as well as not wasting bandwidth on data you aren't going to use.

And if you do, you can combine fields in SQL:

SELECT EmpNo, FName + ' ' + LName AS [Name] FROM Transfer ORDER BY EmpNo


Alternatively to solution #1 by OriginalGriff[^], here is another way:

DataRow dr = ds.Tables["Transfer"].Rows[0];
txt_Name.Text = string.Concat(dr["FNAME"].ToString().Trim(), " ", dr["LNAME"].ToString().Trim());


这篇关于如何组合两个字段以适合表单上的一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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