如何从数据库连接多个coloumns并将其显示在文本框中 [英] How to concatenate multiple coloumns from database and display it in a textbox

查看:91
本文介绍了如何从数据库连接多个coloumns并将其显示在文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单中有一个名称文本框,我想从我的数据库中存在的三个字段first_name,middle_name和last name中获取数据库的值

I have one textbox of name in my form and i want to fetch its value from database from three fields first_name , middle_name and last name present in my database

推荐答案

你没有告诉我们你被困在哪里或者你的问题是什么,所以我将简要介绍一下你需要做什么。



在SQL中,你可以通过执行类似以下操作来轻松连接字段:

You haven't told us where you are stuck or what your question is so I'll briefly go over what you need to do.

In SQL, you can easily concatenate fields by doing something similar to:
SELECT first_name + ' ' + middle_name + ' ' + last_name AS FullName FROM table1





现在,在您的表单中,您使用SqlConnection对象连接到数据库,然后使用DataReader设置文本框值。





Now, in your form you connect to the db with a SqlConnection object and using a DataReader you then set your textbox value.

txtFullName.Text = dr["FullName"].ToString();


这篇关于如何从数据库连接多个coloumns并将其显示在文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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