给mail,发给你
[email protected]

解决方案 »

  1.   

    谢谢!
    真是谢谢你了
    [email protected]
      

  2.   

    private SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass();
    private SQLDMO.NameList sqlServers = null; sqlServers = sqlApp.ListAvailableSQLServers();
    for(int i=0;i<sqlServers.Count;i++)
    {
    object srv = sqlServers.Item( i + 1);
    if(srv != null)
    {
    this.comboBoxServer.Items.Add(srv);
    }
    }
    添加对SQLDMO的引用
      

  3.   

    跟一句:在oracle中sqldmo是什么?
    谢谢!这个问题我文了好久了!
    大家帮忙查一下!
      

  4.   

    以前,我早试过了,但是,到sqlServers = sqlApp.ListAvailableSQLServers();
    就报错了,不知道为什么
      

  5.   

    在.net下用使用sqldmo必须打sql server 2000 sp2的补丁程序!
      

  6.   

    using System;
    using System.Data.SqlClient;
    using System.Data;
    using System.Data.Common;
    using System.Windows.Forms;
    using System.Collections;namespace CustomerLodgingDemo
    {
    /// <summary>
    /// 
    /// </summary>
    public class DataControl
    {
    private SqlConnection sqlconn;
    private SqlCommand sqlcomm;

    public DataControl()
    {
    // 
    // TODO: 在此处添加构造函数逻辑
    //
    sqlconn=new SqlConnection();
    sqlconn.ConnectionString="data source=TORIO005;initial catalog=restaurant;password=hotel;persist security info=True;user id=hotel;workstation id=ALUCARD;packet size=4096";
    sqlcomm=new SqlCommand();
    sqlcomm.Connection=sqlconn;

    } public bool ConnectionTest(string datasource,string account,string password)
    {
    //测试数据库连接是否正常
    SqlConnection newconn=new SqlConnection("data source="+datasource+";initial catalog=restaurant;password="+password+";persist security info=True;user id="+account+";workstation id=ALUCARD;packet size=4096");
    try
    {
    newconn.Open();
    }
    catch
    {
    return false;
    }
    finally
    {
    newconn.Close();
    }
                return true;
    } public void ConnectionModify(string datasource,string account,string password)
    {
    //修改数据库连接字符串
    sqlconn.ConnectionString="data source="+datasource+";initial catalog=restaurant;password="+password+";persist security info=True;user id="+account+";workstation id=ALUCARD;packet size=4096";
    } public void GetCustomerLodgeLog(ref System.Windows.Forms.ListBox roomlog)
    {
    sqlcomm.CommandText="select sleepingroom.name,lodgelog.lodgedate,lodgelog.canceldate from sleepingroom,lodgelog where sleepingroom.id=lodgelog.sleepingroomid";
                sqlconn.Open();
    SqlDataReader reader=sqlcomm.ExecuteReader();
    //MessageBox.Show(reader.FieldCount.ToString());
    //string[] stringarray=new string[];
    try
    {
    while(true)
    {
    string temp="";
    reader.Read();
    Hashtable table=new Hashtable();
    temp+=TimeToDate(reader["lodgeDate"].ToString())+"\t\t";
    temp+=TimeToDate(reader["cancelDate"].ToString())+"\t\t";
    temp+=reader["name"].ToString();
    //MessageBox.Show(temp+"\n"+temp.Length.ToString());
    roomlog.Items.Add(temp);
    }
    }
    catch(Exception e)
    {
    MessageBox.Show(e.Message);
    }
                sqlconn.Close();
    } private string TimeToDate(string time)
    {
    //把时间转换成等字长的日期字串
    string result=time.Substring(0,time.IndexOf(" ",0,time.Length));
    for (int i=0;i<10-result.Length;i++)
    {
    result+=" ";
    }
    //MessageBox.Show(result.Length.ToString());
    return result;
    }
    }
    }
      

  7.   

    不好意思,刚刚贴错了
    using System;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    namespace CustomerLodgingDemo
    {
    public class SqlLocator
    {
    [DllImport("odbc32.dll")]
    private static extern short SQLAllocHandle(short hType, IntPtr inputHandle, out IntPtr outputHandle);
    [DllImport("odbc32.dll")]
    private static extern short SQLSetEnvAttr(IntPtr henv, int attribute, IntPtr valuePtr, int strLength);
    [DllImport("odbc32.dll")]
    private static extern short SQLFreeHandle(short hType, IntPtr handle); 
    [DllImport("odbc32.dll",CharSet=CharSet.Ansi)]
    private static extern short SQLBrowseConnect(IntPtr hconn, StringBuilder inString, 
    short inStringLength, StringBuilder outString, short outStringLength,
    out short outLengthNeeded); private const short SQL_HANDLE_ENV = 1;
    private const short SQL_HANDLE_DBC = 2;
    private const int SQL_ATTR_ODBC_VERSION = 200;
    private const int SQL_OV_ODBC3 = 3;
    private const short SQL_SUCCESS = 0;

    private const short SQL_NEED_DATA = 99;
    private const short DEFAULT_RESULT_SIZE = 1024;
    private const string SQL_DRIVER_STR = "DRIVER=SQL SERVER";

    private SqlLocator(){} public static string[] GetServers()
    {
    string[] retval = null;
    string txt = string.Empty;
    IntPtr henv = IntPtr.Zero;
    IntPtr hconn = IntPtr.Zero;
    StringBuilder inString = new StringBuilder(SQL_DRIVER_STR);
    StringBuilder outString = new StringBuilder(DEFAULT_RESULT_SIZE);
    short inStringLength = (short) inString.Length;
    short lenNeeded = 0; try
    {
    if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_ENV, henv, out henv))
    {
    if (SQL_SUCCESS == SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(IntPtr)SQL_OV_ODBC3,0))
    {
    if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_DBC, henv, out hconn))
    {
    if (SQL_NEED_DATA ==  SQLBrowseConnect(hconn, inString, inStringLength, outString, 
    DEFAULT_RESULT_SIZE, out lenNeeded))
    {
    if (DEFAULT_RESULT_SIZE < lenNeeded)
    {
    outString.Capacity = lenNeeded;
    if (SQL_NEED_DATA != SQLBrowseConnect(hconn, inString, inStringLength, outString, 
    lenNeeded,out lenNeeded))
    {
    throw new ApplicationException("Unabled to aquire SQL Servers from ODBC driver.");
    }
    }
    txt = outString.ToString();
    int start = txt.IndexOf("{") + 1;
    int len = txt.IndexOf("}") - start;
    if ((start > 0) && (len > 0))
    {
    txt = txt.Substring(start,len);
    }
    else
    {
    txt = string.Empty;
    }
    }
    }
    }
    }
    }
    catch (Exception ex)
    {
    //Throw away any error if we are not in debug mode
    #if (DEBUG)
    MessageBox.Show(ex.Message,"Acquire SQL Servier List Error");
    #endif 
    txt = string.Empty;
    }
    finally
    {
    if (hconn != IntPtr.Zero)
    {
    SQLFreeHandle(SQL_HANDLE_DBC,hconn);
    }
    if (henv != IntPtr.Zero)
    {
    SQLFreeHandle(SQL_HANDLE_ENV,hconn);
    }
    }

    if (txt.Length > 0)
    {
    retval = txt.Split(",".ToCharArray());
    } return retval;
    }
    }
    }
      

  8.   

    能否给我一个范例,谢谢![email protected]
      

  9.   

    http://www.csdn.net/develop/article/14/14928.shtm
      

  10.   

    问一下如果只安装了sql的客户端你们的代码能够运行吗?