VB中如何从数据库中获取一行?
你好,我想用 VB 创建一个应用程序。我已经创建了所有表单,同时我想要一个表单连接到数据库(比如说表单名称,DB)。我已经创建了它并连接到 Oracle。现在,在该表单(DB)中,我想搜索 Oracle 表的 ID(我使用 SQL 命令手动创建的)。如果 ID 与用户输入的内容匹配,则该 ID 的所有其他详细信息(例如姓名、地址)都应显示在该表单中!如何做到这一点?任何想法,我是 VB 新手,所以请帮助我!即使您输入代码片段也会很好:)
请告诉我该怎么做?
Hi i want to create a application in VB. And i have created all the forms, and in the meantime i want one form to connect to database(lets say form name, DB). I have created it and connected to Oracle. Now in that form (DB) i want to search the Oracle table for its ID(which have been manually created by me using SQL commands). And if the ID matches with the user entered input, then all other details of that ID(say name, address) should appear in that form! How to do this? Any idea, i'm very newbie in VB, so kindly help me! It will be good even if you put the code snippet :)
Please say me how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有关从 VB .NET 连接到 Oracle DB 的介绍,您可以查看此教程。本文中描述的技术是一种简单快速的入门技术,但是对于生产应用程序,我强烈推荐使用映射器,例如 休眠。一旦您对 Oracle DB 执行了 SQL select 语句,您将需要将已读取的数据复制到对象中以传递到 UI 层:
将所需数据读入内存后,您可以使用数据绑定来显示所需的数据。请阅读这篇文章了解更多相关信息。您需要做的就是在 VB.NET 表单上创建一个控件,并将数据源设置为您从数据库读取的 userObject。
For an introduction on connecting to an Oracle DB from VB .NET you could take a look at this tutorial. The technique described in this article is a simple and fast technique for getting started, however for production applications I would strongly recommend a mapper such as Nhibernate. Once you have performed your SQL select statement against the Oracle DB you will need to copy the data that you have read into an object to pass up to the UI layer:
Once you have read the required data into memory you could use data binding to display the required data. Read more about it in this article. All you should need to do is create a control on your VB.NET form, and set the datasource the your userObject that you have read in from the database.
你的命令用了什么?您可以使用命令传递 ID,以便查询只会返回您想要的结果。所以查询看起来像“select * from mytable where ID = 1”。 1 的 id 来自 vb 应用程序,您可以将其作为参数传递,也可以在应用程序中构建查询并以文本形式运行查询。到目前为止你有什么?
what have you been using for your commands? you would pass the ID with the command so the query would only return the results that you would want. So the query would look something like "select * from mytable where ID = 1". the id of 1 would be from the vb application which you would either pass it as a parameter or build the query in the application and just run the query as text. what have you so far?