Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C读取SQL表和视图_C#_Sql_Views - Fatal编程技术网

C# C读取SQL表和视图

C# C读取SQL表和视图,c#,sql,views,C#,Sql,Views,我目前正在读取SQL数据库中的表列表,并用表名填充一个组合框。我想在同一个列表中包含SQL视图。表的sysobjects类型为“U”,视图的sysobjects类型为“V”。如何更改odbc命令行以检索U和V?谢谢 OdbcConnection cn=getConnection(); OdbcCommand cmdList; cmdList = new OdbcCommand("select name, user_name(uid) from sysobjects where type='U

我目前正在读取SQL数据库中的表列表,并用表名填充一个组合框。我想在同一个列表中包含SQL视图。表的sysobjects类型为“U”,视图的sysobjects类型为“V”。如何更改odbc命令行以检索U和V?谢谢

OdbcConnection cn=getConnection(); 
OdbcCommand cmdList; 
cmdList = new OdbcCommand("select name, user_name(uid) from sysobjects where type='U'",cn);
cn.Open();

        OdbcDataReader reader = cmdList.ExecuteReader();
        while (reader.Read())
        {
            for (int i=0;i<reader.FieldCount;i++)
            {
                if (!reader.IsDBNull(i))
                {
                    if (reader.GetName(i).ToUpper()=="NAME")
                    {
                            comboBoxTables.Items.Add(reader.GetString(i));
                    }
                }
            }
        }
cn.Close();
尝试:

尝试:


您使用的是什么版本的SQL Server?如果它超过了Sql 2000,请不要使用sysobjects,因为它已被弃用。改用sys.objects


此外,您可能应该使用SMO SQL Server管理对象,而不是编写自己的查询。

您使用的是什么版本的SQL Server?如果它超过了Sql 2000,请不要使用sysobjects,因为它已被弃用。改用sys.objects


另外,您可能应该使用SMO SQL Server管理对象,而不是编写自己的查询。

为什么我不试试呢!谢谢我为什么没试过!谢谢
"... where type='U' or type='V'"