如何在VB.NET中连接sql数据库? [英] How to connect the sql database in VB.NET?

查看:115
本文介绍了如何在VB.NET中连接sql数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我创建模块"mod_conn"&创建函数getconnect()&该函数中给出的以下编码


公共函数getconnect()
连接=新的SqlConnection(提供程序=用于SQL Server数据源的Microsoft OLE DB提供程序= VINAYAK-67DE19C \ SQLEXPRESS;初始目录= UA;用户ID = sa密码= sulos";)
最终功能

但这不是从sql数据库中提取数据

Hi,

I create the module "mod_conn" & create function getconnect() & the following coding given in that function


Public Function getconnect()
connection = New SqlConnection("Provider=Microsoft OLE DB Provider for SQL Server Data Source=VINAYAK-67DE19C\SQLEXPRESS;Initial Catalog=UA;User ID=sa password=sulos";)
End Function

But it is not pull data from the sql database

推荐答案

尝试在您的UserID之后添加;"!

(顺便说一句:不要在论坛上发布用户名和密码!这是养成安全习惯的好主意:规则1-永远不要告诉全世界您的密码...:doh:)
Try adding a '';'' after your UserID!

(BTW: Don''t post user id and password to forums! It''s a good idea to get into the habit of security: Rule 1 - never tell the whole world your password... :doh: )


您不需要SqlClient的提供程序名称,因为它默认情况下连接到Sql Server提供程序.

所以您的Connectionstring应该是
数据源= VINAYAK-67DE19C \ SQLEXPRESS;初始目录= UA;用户ID = sa;密码= sulos;"

随身更改,然后尝试使用
connection.Open()打开连接,希望它能正常工作.

欢呼
You dont need Provider name for SqlClient as it connects to the Sql Server provider by default.

So your Connectionstring should be
"Data Source=VINAYAK-67DE19C\SQLEXPRESS;Initial Catalog=UA;User ID=sa;password=sulos;"

Change it with yours, and try to use
connection.Open() to open the connection, I hope it will be working.

Cheers


仅打开连接并不会为您提取数据.
您需要使用数据集或数据读取器.
Just opening a connection is not going to pull the data for you.
You need to use a dataset or datareader.


这篇关于如何在VB.NET中连接sql数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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