C#使用Access数据库,怎样根据某个已知的字段,获取其对应的其他字段的值?

2024-12-20 06:52:21
推荐回答(2个)
回答1:

object o=null;
using (OleDbConnection con = new OleDbConnection(connectionStr))
{
string query = string.Format("select top 1 STUname from form1 where username = '{0}',username);

using(OleDbCommand cmd = new OleDbCommand(query,con)
{
con.Open();
object o = cmd.ExecuteScalar();//根据你的STUname
数据类型,再将 o 转换成相应的类型,比如 是字符串 就可以 string s = o.ToString();

}

}

回答2:

根据那个字段查询 “select * from `form1` where `username`='xxx'”