如何在标签上显示访问数据库数据 [英] How to display access database data on label
本文介绍了如何在标签上显示访问数据库数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将Access中的数据库数据显示为标签。这是我的代码:
I want to display database data from Access into a label. Here is my code:
string connectString = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=D:/_Web3rev/App_Data/CentralDB.mdb";
OleDbConnection cn = new OleDbConnection(connectString);
cn.Open();
string selectString = "SELECT studid FROM Students WHERE studid='" + lblStudid.Text+ "'";
OleDbCommand cmd = new OleDbCommand(selectString, cn);
OleDbDataReader reader = cmd.ExecuteReader();
我想将数据库内容显示到根据用户条目标记。谢谢。
I want to display database content into label as per user entry. Thanks.
推荐答案
根据上面的评论,这工作了
As per the comments above, this worked
if(reader.Read())
lblstudid.text = reader.GetString(reader.GetOrdinal("studid"));
and get rid of the while {}
这篇关于如何在标签上显示访问数据库数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文