使用c#从两个内部连接表中的sql server数据库获取具有相同列名的数据 [英] get data from sql server database in two inner join tables which has a same column name using c#
问题描述
现在我使用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屋!