填充:selectcommand.connection属性尚未初始化。我的代码plzzz的错误有什么帮助 [英] Fill: selectcommand.connection property has not been initialized. What error of my code plzzz help

查看:115
本文介绍了填充:selectcommand.connection属性尚未初始化。我的代码plzzz的错误有什么帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 dbconn.Open()
dbadapter.SelectCommand = New OleDb.OleDbCommand
dbadapter.Fill(dbdataset1)
dbconn.Close()
Me.DataGridView1.DataSource = dbdataset1.Tables( 0 )。DefaultView





我尝试了什么:



在vb.net上填写datagridview im newbie

解决方案

您不仅没有初始化Command对象的Connection属性,也没有初始化它的CommandText属性。您如何看待数据库应该知道您想要什么?



如果您只打算使用单个DataTable,那么没有理由使用DataSet - DataAdapter .Fill(..)方法也可以接受一个DataTable作为参数。



你应该使用使用 - OleDb ***的声明 - 对象以安全地释放相关资源。



请查看此CodeProject文章,您将从中学习如何做到这一切:



正确执行数据库操作 [ ^ ]

dbconn.Open()
dbadapter.SelectCommand = New OleDb.OleDbCommand
dbadapter.Fill(dbdataset1)
dbconn.Close()
Me.DataGridView1.DataSource = dbdataset1.Tables(0).DefaultView



What I have tried:

fill datagridview im newbie on vb.net

解决方案

You didn't just not initialize the Connection-property of your Command-object, you also didn't initialize the CommandText-property of it. How do you think the database should know what you want?

Also there's no reason to use a DataSet if you're only going to use a single DataTable - the DataAdapter.Fill(..) method can also accept a DataTable as argument.

And you should be using using-statements for your OleDb***-objects in order to securely free the associated resources.

Please take a look at this CodeProject article, you'll learn from it how to do all this properly:

Properly executing database operations[^]


这篇关于填充:selectcommand.connection属性尚未初始化。我的代码plzzz的错误有什么帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆