String connstr = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=F:\WebSite5\App_Data\db1.mdb;";        OleDbConnection myConnection = new OleDbConnection(connstr);
        myConnection.Open();
        OleDbCommand myCommand = new OleDbCommand("select 题目 from 题目 where ID=1", myConnection);
        //DataSet ds = new DataSet();
        //OleDbDataAdapter adr = new OleDbDataAdapter(myCommand);
        //adr.Fill(ds, "题目");        this.Label1.Text = myCommand.ToString(); 
        myConnection.Close();运行了以后出来的是:System.Data.OleDb.OleDbCommand 
请问一下 我哪里写错误了???我想让 label  读取 数据库的内容。。在线等!!!急!!!!!!

解决方案 »

  1.   

    参考,你的access什么版本?
    using System;   
    using System.Collections.Generic;   
    using System.Text;   
    using System.Data;   
    using System.Data.OleDb;   
    using System.Data.SqlClient;   
      
    namespace TestAccess   
    {   
        class Program   
        {   
            static void Main(string[] args)   
            {  
                #region Access 2007   
                Console.WriteLine("Access 2007");   
                string strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;";   
                strConnection += @"Data Source=C:\Documents and Settings\v-changl\My Documents\Database1.accdb;";   
                strConnection += "Persist Security Info=False";   
                using (OleDbConnection objConnection = new OleDbConnection(strConnection))   
                {   
                    objConnection.Open();   
                    OleDbDataAdapter myCommandd = new OleDbDataAdapter("select * from Couse", objConnection);   
                    DataSet ds = new DataSet();   
                    myCommandd.Fill(ds, "couse");   
                    DataTable dt = ds.Tables["couse"];   
                    Console.WriteLine(dt.Columns[0].ToString());   
                    Console.WriteLine(dt.Columns[1].ToString());   
                    Console.WriteLine(dt.Columns[2].ToString());   
      
                    objConnection.Close();   
      
                }  
                #endregion   
    }   
    }   
    }  
    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/LCL_data/archive/2009/05/06/4154255.aspx
      

  2.   

    ACCESS的版本是2003的··谢谢你提供的帮助··不过 改了一下
    OleDbConnection myConnection = new OleDbConnection(connstr);
            myConnection.Open();
           // OleDbCommand myCommand = new OleDbCommand("select 题目 from 题目 where ID=1", myConnection);
            
            OleDbDataAdapter adr = new OleDbDataAdapter("select 题目 from 题目 where ID=1", myConnection);
            DataSet ds = new DataSet();
            adr.Fill(ds, "题目");
            DataTable dt = ds.Tables["题目"];   
            this.Label1.Text = dt.ToString(); 提示:adr.Fill(ds, "题目");有异常问题···
      

  3.   

    不会吧,貌似都对的啊!清空缓存,重新生成下,IIS重启
      

  4.   

    DataSource的路径是不是写错了?F:\\WebSite5
      

  5.   

    if(ds.Tables["题目"].Rows.Count>0)
    {
    this.Label1.Text = ds.Tables["题目"].Rows[0][0].ToString();
            
    }
      

  6.   

    什么异常啊?
    select [题目] from 题目 where ID=1
      

  7.   

    7楼 刚又跑了一下 还是adr.Fill(ds, "题目");   提示OleDbException  用户未处理问题,我的开头是using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.OleDb;
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {这样写的 ··是不是 哪里出问题了??
      

  8.   

    写出来了· · 这个真谢谢大家··给我提供了这么大的支持··最后还是要特别感谢下··LCL_data、wuyq11      感谢大家的支持。
    揭晓下:成果语句:ExecuteScalar.靠它省了很多东西···
      

  9.   

    厉害this.Label1.Text = myCommand.ToString();不过更厉害的是没人看明白。建议楼主找本书认真地看看ADO.net.