在给定数据库名称的情况下检索表名称

编程入门 行业动态 更新时间:2024-10-27 11:17:46
本文介绍了在给定数据库名称的情况下检索表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在编写一个程序来在C#中的db中添加/编辑表中的表项. 我想知道是否可以通过给定数据库名称来检索表名称,例如northwind. 在这方面,请帮我,因为我一直坚持下去. 在此先感谢.

I am writing a program to add/edit table enteries in a db in c# I want to know whether we will be able to retrieve table names given a database name,say northwind. please help me in this regard,as i am stuck with it. Thanks in advance.

推荐答案

以下内容将在大多数RDBM服务器上起作用: The following will work on most RDBM servers : select * from INFORMATION_SCHEMA.TABLES

返回的实际列可能因服务器类型而异,但核心列TABLE_NAME等都存在.

The actual columns returned might vary between server types but the core ones TABLE_NAME etc. exist in all.

Try: Try: using (SqlConnection con = new SqlConnection(strCon)) { con.Open(); using (SqlCommand cmd = new SqlCommand("SELECT * FROM dbo.sysobjects WHERE xtype = 'U'", con)) { using (SqlDataReader r = cmd.ExecuteReader()) { while (r.Read()) { Console.WriteLine(r["name"]); } } } }

更多推荐

在给定数据库名称的情况下检索表名称

本文发布于:2023-10-17 11:10:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500718.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   情况下   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!