select * from  crmManager.用户名.SYSOBJECTS  where xtype='u' 你的语句写成这样应该能行的,怎么不行了?

解决方案 »

  1.   

    Initial Catalog=crmManager
    其实你默认连接的就是那个数据库,应该不会出错了
      

  2.   

    估计你的问题解决不了了 我这里确实没问题create database crmManager 
    go
    create table Autocar(id int)
    go
    create table Categories(id varchar(10))
    go
    create table Manufacturer(id varchar(10))
    go select * from  SYSOBJECTS  where type='u'
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data;
    using System.Data.SqlClient;namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                SqlConnection conn = new SqlConnection("Server=localhost\\sql2005;database=crmManager;uid=sa;pwd=");
                try
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("select * from SYSOBJECTS  where type='u'", conn);
                    //我试了下 可以的 不知道你的怎么不可以 
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Console.WriteLine(reader["name"]);
                    }
                }
                catch(Exception e){
                    Console.WriteLine(e.Message);    
                }
                finally 
                {
                    conn.Close();                
                }
            }
        }
    }E:\>csc Test.cs
    Microsoft (R) Visual C# 2005 编译器 版本 8.00.50727.1433
    用于 Microsoft (R) Windows (R) 2005 Framework 版本 2.0.50727
    版权所有 (C) Microsoft Corporation 2001-2005。保留所有权利。
    E:\>Test
    Autocar
    Categories
    ManufacturerE:\>
      

  3.   

    同意,
    呵呵,你先读取看看先,不绑定到COMBOBOX
      

  4.   


    连接字符串中要指定你的数据库名
    [code=C#]
    string strcon = "server=.;uid=sa;pwd=;database=你的数据库名";
    SqlConnection sqlcon = new SqlConnection(strcon);
    string cmdtxt = "select [name],[id] from sysobjects where xtype='u' and status>0 order by name";
    SqlDataAdapter sqlda = new SqlDataAdapter(cmdtxt, sqlcon);
    DataTable dt = new DataTable();
    sqlda.Fill(dt);数据表绑定COMBOBOX
      

  5.   

    6楼的补充
    comboBox1.DataSource = dt;
    comboBox1.DisplayMember = "name";
    //comboBox1.ValueMember = "name";
      

  6.   

    DataSet ds =new DataSer();
    using(SqlConnection con = new SqlConnection(""))
    {
    string sql= "select * from  dbo.SYSOBJECTS  where xtype='u'";
    SqlDataAdapter da = new SqlDataAdapter(sql, con);
    da.Fill(ds);
    }
    comboBox1.DataSource = ds; 
    comboBox1.DisplayMember = ""; 
    comboBox1.ValueMember = "";