使用c#从两个内部连接表中的sql server数据库获取具有相同列名的数据 [英] get data from sql server database in two inner join tables which has a same column name using c#

查看:297
本文介绍了使用c#从两个内部连接表中的sql server数据库获取具有相同列名的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我使用c#从sql server数据库中获取所有数据。


sql命令是内连接查询,table_1内连接table_2。如下所示:


sqlcmd =" select table_1。*,table_2。* from table_1 inner join table_2 on table_1.id = table_2.id"


table_1和table_2中的列名称temp_id相同。


和 那么我想从结果数据表中获取table_1中的temp_id(比如使用xx.Rows [0] [" temp_id"]),怎么做?


谢谢

解决方案

将select语句更改为"select table_1。*,"然后 拼写table_2中"table_2.fieldname"的所有字段名称。格式并跳过"temp_id"那里。

now i use c# to get all the data from a sql server database.

the sql command is a inner join query, table_1 inner join table_2. like the following:

sqlcmd = "select table_1.*, table_2.* from table_1 inner join table_2 on table_1.id = table_2.id "

there is a same column name temp_id in both the table_1 and table_2.

and  then i want to only get the temp_id in table_1 from the resulted datatable (like use xx.Rows[0]["temp_id"]), how to do it?

thanks

解决方案

Change the select statement to "select table_1.*, " then spell all the field names on table_2 in "table_2.fieldname" format and skip "temp_id" there.


这篇关于使用c#从两个内部连接表中的sql server数据库获取具有相同列名的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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