建立连接 [英] Creating Connection
本文介绍了建立连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在sql 2008中有两个表,并且我有一个项目,在VB.Net中是我的项目的首页,而在SQL2008中,我是该两个表,现在我在SQL表和VB.Net之间存在连接问题. br/>
我不知道如何用VB.Net连接表
您能帮忙指导我如何解决此问题吗?
谢谢
Amin
I have two table in sql 2008 and i have one project i made the front page of my project in VB.Net and i made that two table in SQL2008 now i have problem with connection between SQL table and VB.Net.
I don''t know how to connect the Tables with VB.Net
Can you please help to guide that how can i solve this problem.
Thanks
Amin
推荐答案
我要说的是,您应该掌握一本有关基本VB.Net的好书,并使用SQLConnection,SQLCommand,SQLDataReader等方法来研究ADO.Net. .
学习愉快
I would say that you should get hold of a good book on basic VB.Net and study up on ADO.Net using SQLConnection, SQLCommand, SQLDataReader etc methods.
Happy Learning
阅读有关ADO.NET的信息,它将对您有所帮助.
看看这些:
MSDN:ADO.NET [使用DataReader,SQL Server [ C#Station ADO.NET教程 [
Read about ADO.NET and it will help you.
Look at these:
MSDN: ADO.NET [^]
Using DataReaders, SQL Server [^]
The C# Station ADO.NET Tutorial[^]
请按照以下步骤操作
1.如果数据库名称是:NorthWindDB.
2.在web.config文件中添加以下代码.
< connectionString>
< add name ="NorthWindDB" value ="Server = machinename \ SQLEXPRESS; Database = NorthWindDB; User Id = sa; password = dss;" />
</connectionString>
3.在代码文件中,导入以下名称空间.
导入System.Data;
导入System,Data.SqlClient;
4.添加对System.Configuration命名空间的引用.右键点击项目->点击添加参考->选择System.Configuration->好的.
编写以下代码以连接到数据库并执行查询"select * from Emp".此查询检索NorthWindDB数据库的Emp表中的所有行.
5.将昏暗状态设置为新的SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("NorthWindDB").ConnectionString()
将cmd设置为New SqlCommand(con,从emp中选择*")
暗博士为SqlDataReader = cmd.ExecuteReader()
while(dr.Read())
//根据您的要求处理数据.
结束时
< a href ="http://dotnetforbeginner.blogspot.com/"> http://dotnetforbeginner.blogspot.com/</a>< a href ="http://dotnetforbeginner.blogspot.com/"target =" _ blank"title ="新窗口></a>
Please follow the below steps
1. If the database name is : NorthWindDB.
2. in web.config file add the following code.
<connectionString>
<add name="NorthWindDB" value="Server=machinename\SQLEXPRESS;Database=NorthWindDB;User Id=sa;password=dss;" />
</connectionString>
3. In the code file, import the following namespaces.
Imports System.Data;
Imports System,Data.SqlClient;
4. Add the reference to System.Configuration namespace. By right clicking the project-> click Add Reference -> select System.Configuration -> ok.
Write the following code to connect to the database and execute the query "select * from Emp". This query retreives all the rows from the Emp table of the NorthWindDB database.
5.Dim con as New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("NorthWindDB").ConnectionString()
dim cmd as New SqlCommand(con,"select * from Emp")
dim dr as SqlDataReader = cmd.ExecuteReader()
while(dr.Read())
//Process the data as per your requirement.
End While
<a href="http://dotnetforbeginner.blogspot.com/">http://dotnetforbeginner.blogspot.com/</a><a href="http://dotnetforbeginner.blogspot.com/" target="_blank" title="New Window"></a>
这篇关于建立连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文