解决方案 »

  1.   

    你是做网站要读取数据   还是其他的 ?
    首先是 基于ASP的 数据库连接 :在web.config 里面写连接 :
    <configuration>
    <appSettings>
    <add key="connstr" value="database =数据库名(Apriori);server=(mssql服务器名);Integrated Security=True"></add>
    </appSettings>
    <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    </system.web>
    </configuration>然后页面调的代码 :假设按钮的操作:
    private void button1_Click(object sender ,EventArgs e)
    {
        connstr = System.Configuration.ConfigurationSettings.AppSettings["connstr"].ToString();  //获取连接数据库的字符串。该字符串在web.config里面
        conn = new SqlConnection(connstr);     //实例化SqlConnection对象。connStr是数据库链接字符串
        conn.open();   //打开数据库连接    SqlCommand cmd = new SqlCommand();//创建一个数据命令对象sqlcommand
        cmd.Connection = conn;//设置connection属性
        cmd.CommandText="select * from  Myminingdata(表名)";//需要执行的SQL语句
        cmd.CommandType=CommandType.Text;// 使其只执行SQL语句文本形式
        SqlDataReader sdr=cmd.ExcuteReader();// 使用ExcuteReader()方法实例化一个SqlDataReader 对象。
    }还有是直接 的链接数据库获取表中信息的 :
    Sqlconnection conn;
    {
        conn = new SqlConnection("server=服务器名;database=数据库名;uid=sa(用户名);pwd=用户自己设的密码");     //实例化SqlConnection对象。
        conn.open();   //打开数据库连接    SqlCommand cmd = new SqlCommand();//创建一个数据命令对象sqlcommand
        cmd.Connection = conn;//设置connection属性
        cmd.CommandText="select * from  Myminingdata(表名)";//需要执行的SQL语句
        cmd.CommandType=CommandType.Text;// 使其只执行SQL语句文本形式
        SqlDataReader sdr=cmd.ExcuteReader();// 使用ExcuteReader()方法实例化一个SqlDataReader 对象
    }应该看得懂吧?!