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 读取 数据库的内容。。在线等!!!急!!!!!!
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 读取 数据库的内容。。在线等!!!急!!!!!!
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
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, "题目");有异常问题···
{
this.Label1.Text = ds.Tables["题目"].Rows[0][0].ToString();
}
select [题目] from 题目 where ID=1
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)
{这样写的 ··是不是 哪里出问题了??
揭晓下:成果语句:ExecuteScalar.靠它省了很多东西···