读取和写入SQL数据库 [英] Reading from and writing to an SQL database

查看:93
本文介绍了读取和写入SQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一位经验丰富的VB6用户,并且已经从VB6代码中多次读取和写入SQL数据库,但是我一直在努力寻找与VB.NET等效的东西.我在VB6中使用了ADO.我假设我将ODBC与VB.NET一起使用,因为(显然)不支持ADO.

I am an experienced VB6 user and have read from and written to SQL databases many times from VB6 code but I am struggling to find the VB.NET equivalents. I used ADO with VB6. I presume I use ODBC with VB.NET as ADO is not (apparently) supported. Do you have any code examples which perform these functions?

推荐答案

具有VB.NET/C#的ADO.NET可以读写数据. >
在此处阅读有关ADO.NET的信息,它将对您有所帮助:
MSDN:ADO.NET [ MSDN:使用ADO.NET访问数据 [ ^ ]

CP档案:
为初学者使用ADO.NET [简单的ADO.NET数据库读取,插入,更新和删除使用C#. [ ^ ]
It''s ADO.NET with VB.NET/C# to read-write data.

Read about ADO.NET here and it will help you:
MSDN: ADO.NET[^]
MSDN: Accessing Data with ADO.NET[^]

CP archive:
Using ADO.NET for beginners[^]
Simple ADO.NET Database Read, Insert, Update and Delete using C#.[^]




这是在vb.net中使用sql数据库的示例代码.
使用Visual Studio 2008中的服务器资源管理器工具创建数据库,如下所示:

1.右键单击数据连接->添加连接
如果数据源是"Microsoft SQL Server数据库文件(SqlClient)"
然后只需键入数据库名称,然后单击确定"

2.只需选择数据库文件,然后按F4,它将焦点设置为数据库属性
3.从属性复制连接字符串.
4.开始执行以下操作,

Dim con As New SqlConnection(在此处粘贴您的连接字符串")
将cmd作为sqlcommand
cmd = new sqlcommand(从table_name中选择*",con)
"在上面的语句中,我已经输入了sql命令的命令文本和连接属性
con.open()
cmd.executenonquery()
con.close()

就这样

谢谢

Ganesh
Hi,

Here is a sample code to use sql database in vb.net

Create database using the server explorer tool in visual studio 2008 as

1. Right Click on Data Connection -> Add Connection
If the data source is ''Microsoft SQL Server Database File (SqlClient)''
then just type the database name and click OK

2. Just select the data base file and press F4 it sets focus to database properties
3. Copy the connection sting from properties.
4. Start doing as below,

Dim con As New SqlConnection("Past your connection string here")
dim cmd as sqlcommand
cmd=new sqlcommand("Select * from table_name", con)
''In the above statement I''ve enter the command text and connection property for the sql command
con.open()
cmd.executenonquery()
con.close()

That is all

Thank You,

Ganesh


这篇关于读取和写入SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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