oledbCommand1.CommanText="select xm from yourtable where id=2";
string str=OleDbCommand1.ExecuteScalar();

解决方案 »

  1.   

    using System.Data;
    using System.Data.OleDb;....string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:\yourdatabasename.mdb";
    string strSql = "SELECT xm FROM Table1 Where ID=1";
    OleDbConnection conn = new OleDbConnection(strConn);
    OleDbCommand cmd = new OleDbCommand(strSql,conn); try
    {
    conn.Open();
    string s = (string)cmd.ExecuteScalar();
    MessageBox.Show(s);
    }
    catch(Exception ex)
    {
    MessageBox.Show("打开数据库出错: " + ex.ToString());
    }
    finally
    {
    conn.Close();
    }