如何从紧凑数据库中读取列
我正在使用 C# 2010 Express 和 Sql Compact。我有一个名为“记录”的表和名为“名称”的列,我想在列表框中列出这些名称。
我编写了该代码,但最后一行是“ExecuteReader:连接属性尚未初始化。”例外。
SqlCeConnection Baglan = new SqlCeConnection("Data Source=|DataDirectory|CeoDatabase.sdf;Password=CeoDB;Persist Security Info=True");
Baglan.Open();
SqlCeCommand BarlariAl = new SqlCeCommand("SELECT Names FROM Barlar");
SqlCeDataReader BarlariOku = BarlariAl.ExecuteReader();
I'm using C# 2010 Express and Sql Compact. I have a table named as "Records" and column named as "Names" I want to list that names in a listbox.
I wrote that code but last line is thorws "ExecuteReader: Connection property has not been initialized." exception.
SqlCeConnection Baglan = new SqlCeConnection("Data Source=|DataDirectory|CeoDatabase.sdf;Password=CeoDB;Persist Security Info=True");
Baglan.Open();
SqlCeCommand BarlariAl = new SqlCeCommand("SELECT Names FROM Barlar");
SqlCeDataReader BarlariOku = BarlariAl.ExecuteReader();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
至于接下来要写什么,假设有一个名为
listbox
的列表框(给定变量名称的大胆假设),您可以这样写:顺便说一句,您没有正确处理对象。它应该看起来像这样:
As to what to write next, assuming there's a list box named
listbox
(bold assumption given your variable names), you'd write:As an aside, you're not disposing your objects properly. It should look like this:
您没有将连接与命令关联起来。尝试下面的代码。
要列出列,请尝试从 MSDN(添加右大括号)。
You're not associating the connection with the command. Try the code below.
For listing the columns, try this code borrowed from MSDN (with closing braces added).