高分求助:如何把access表中某个字段的值取出并赋给一个变量? oledbCommand1.CommanText="select xm from yourtable where id=2";string str=OleDbCommand1.ExecuteScalar(); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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(); } 备份数据库时出错!!! 如果把窗体文件加入新的工程项目中? C# 怎么判断FTP是否连接上? 实现了接口,跟拥有的功能 申請login怎么寫 输入输出流操作时丢失数据的问题 关于定时器的一个奇怪的问题。 如何改变函数参数的值 微软在CSDN里面布置了多少傀儡啊? 如何打印DataGrid 中内容((win form)) DataGrid问题,着急!!! 问一下,在c#中对图片的处理要怎么做?
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();
}