在工程里找到Microsoft ADO Data Control控件,拖到窗体上,事件中这么写:
Private Sub Coammand1_Click()
Adodc1connectionstring="Driver={SQL Server};Server=服务器IP;Uid=用户名;Pwd=密码;DataBse=数据库名"
Adodc1RecordSource="SELECT FROM 表名 WHERE 条件"
Adodc1Refrsh
End Sub
要进行数据 *** 作就这样引用:
Adodc1RecordSetFields("字段名")这就是 *** 作数据字段
把Adodc1绑定到数据控件那就是绑定数据源
方法如下:
第一种连接和记录集分开声明
<%
db="db/dardenmdb"
set conn=servercreateobject("ADODBconnection")
connstr="Provider=MicrosoftJetOLEDB40;Data Source=" & ServerMapPath("" & db & "")
connopen connstr
%>
<%
set rs=servercreateobject("adodbrecordset")
sql="select from ebook order by id desc"
rsopen sql,conn,3,3
rsaddnew
rsupdate (rsdelete)
rsclose
set rs=nothing
connclose
set conn=nothing
responsewrite("<center><a href=viewdatabaseasp>显示文字</a></center>")
ResponseRedirect "homepageasp"
%>
第二种连接和记录集一同声明
<%
set rs=servercreateobject("adodbrecordset")
sql="select from ebook order by id desc"
conn = "DBQ=" + servermappath("bookmdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (mdb)};"
rsopen sql,conn,3,3
rsaddnew
rsupdate (rsdelete)
rsclose
set rs=nothing
responsewrite("<center><a href=viewdatabaseasp>显示文字</a></center>")
%>
ASP数据库简单作教程
<1>数据库连接(用来单独编制连接文件connasp)
<%
Set conn = ServerCreateObject(ADODBConnection)
connOpen DRIVER={Microsoft Access Driver (mdb)}; DBQ= & ServerMapPath(\bbs\db1\usermdb)
%>
-、用DAO控件连接数据库1与Access2000数据库连接Private Sub Command1_Click()'也可直接在控件属性中设置以下各项但在控件属性中不能写入密码'只有在数据数没有密码的情况下可以省略Data1RefreshData1Connect = "Access 2000;"Data1DatabaseName = App Path + "/chncmadbmdb"'数据库没有密码此句可省Data1Connect = ";pwd=123456"'Data1RecordSource = "耕地资源管理单元属性数据表2004" Data1RecordSource = "select from耕地资源管理单元属性数据表2004"Data1Refresh’move后才能正确显示记录个数End Sub2与没有密码的DBF文件数据库连接Private Sub Command2_Click()Data1Connect = "dBASE III;"Data1DatabaseName = App Path' Data1RecordSource ="DBF"Data1RecordSource = "select from dbf"Data1Refresh’move后才能正确显示记录个数End Sub3与没有密码的Excel文件数据库连接Private Sub Command3_Click()Data1Connect = "Excel 80;"Data1DatabaseName = AppPath & "/EXcelxls"Data1RecordSource = "select from [EXcelxls]"Data1Refresh’move后才能正确显示记录个End Sub 二、用DAO代码连接数据库'在使用DAO对象前应选定Visual Basic菜单下的[工程]中的引用了菜单中的[Microsoft DAO 36 Object Library]选项,或其它版本1DAO代码与Access数据库连接Private Sub Command1_Click()Dim Db As DatabaseDim Rs As Recordset'以共享、读写方式打开'如果无密码最后一个参数可以不要Set Db= OpenDatabase(AppPath & "/chncmadbmdb", False, False, ";pwd=123456")'不需要move来更新记录个数 'Set Rs = DbOpenRecordset("耕地资源管理单元属性数据表2004") '需要move来更新记录个数Set Rs = DbOpenRecordset("select from [耕地资源管理单元属性数据表2004]")If RsRecordCount > 0 Then RsMoveLast RsMoveFirstEnd IfEnd Sub 2DAO代码与没有密码的DBF文件数据库连接Private Sub Command2_Click()Dim Db As DatabaseDim Rs As Recordset'以共享、读写方式打开Set Db = OpenDatabase(AppPath, False, False, "dbase III;") '不需要move来更新记录个数'Set Rs = DbOpenRecordset("DBF")’需要move来更新记录个数Set Rs = DbOpenRecordset("select from [DBF]") If RsRecordCount > 0 Then RsMoveLast RsMoveFirstEnd IfEnd sub 3 'DAO代码与没有密码的Excel文件数据库连接Private Sub Command3_Click()Dim Db As DatabaseDim Rs As Recordset'以共享、读写方式打开'如果无密码最后一个参数可以不要Set Db = OpenDatabase(AppPath & "/EXcelxls", False, False, "Excel 80;")'不需要move来更新记录个数 ' Set Rs = DbOpenRecordset("EXcelxls") '表格中的工作目录sheet '需要move来更新记录个数Set Rs = DbOpenRecordset("select from [EXcelxls]") '表格中的工作目录sheet'If RsRecordCount > 0 Then RsMoveLast RsMoveFirstEnd IfEnd Sub 三、用ADO控件连接数据库'也可直接在控件属性中设置以下各项1ADO控件与Access2000数据库连接Private Sub Command1_Click() '连接有密码的Access数据库 'Adodc1ConnectionString = "Provider=MicrosoftJetOLEDB40;Data Source=" & AppPath & "/chncmadb1mdb;Jet OLEDB:DataBase PASSWORD=123456" '连接没有密码的Access数据库 Adodc1ConnectionString = "Provider=MicrosoftJetOLEDB40;Data Source=" & AppPath & "/chncmadbmdb;Persist Security Info=False" 'Adodc1RecordSource = "[耕地资源管理单元属性数据表2004]" Adodc1RecordSource = "select from [耕地资源管理单元属性数据表2004]" Adodc1Refresh Set DataGrid1DataSource = Adodc1 DataGrid1RefreshEnd Sub 2'ADO控件与DBF表连接Private Sub Command2_Click() 'Adodc1ConnectionString = "Provider=MSDASQL1;Persist Security Info=False;Data Source=dBASE Files;DBQ=" & AppPath & ";SourceType=DBF;" 'Adodc1ConnectionString = "Provider=MSDASQL1;Persist Security Info=False;Extended Properties=DSN=Visual FoxPro Tables;UID=;SourceDB=”& apppath &”;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;" 'Adodc1ConnectionString = "Provider=MSDASQL1;Persist Security Info=False;Extended Properties=DSN=dBASE Files;DBQ=”& apppath &”;;DefaultDir=”& apppath &”;DriverId=533;MaxBufferSize=2048;PageTimeout=5;" '能使表名长度不受限制 Adodc1ConnectionString = "Provider=MSDASQL1;Driver=Microsoft Visual Foxpro Driver;SourceDB=" & AppPath & ";SourceType=DBF;Locale Identifier=2052" 'Adodc1RecordSource = "[DBF1]" Adodc1RecordSource = "select from DBF1" Adodc1Refresh Set DataGrid1DataSource = Adodc1 DataGrid1RefreshEnd Sub 3'ADO控件与Excel表连接Private Sub Command3_Click() '下面一句测试未能通过 'Adodc1ConnectionString = "Data Provider=MSDASQL1;driver=Microsoft Excel Driver xls);DBQ=" & AppPath & "/EXcelxls" 'Adodc1ConnectionString="Provider=MSDASQL1;Persist Security Info=False;Extended Properties=DSN=Excel Files;DBQ=" & AppPath & "/EXcelxls;DefaultDir=”&apppath &”;DriverId=790;MaxBufferSize=2048;PageTimeout=5;" Adodc1ConnectionString = "Provider=MicrosoftJetOLEDB40;Persist Security Info=False;Data Source=" & AppPath & "/EXcelxls;Extended Properties='Excel 80;HDR=Yes'" 'Adodc1RecordSource = "[EXcelxls]" Adodc1RecordSource = "select from [EXcelxls]" Adodc1Refresh Set DataGrid1DataSource = Adodc1 DataGrid1RefreshEnd Sub 4'ADO控件与Oracle数据库连接Private Sub Command4_Click() 'Adodc1ConnectionString = "Provider=MSDAORA1;Password=chncmadb;User ID=chncmadb;Data Source=towebserver;Persist Security Info=True"Adodc1ConnectionString="Provider=OraOLEDBOracle1;Password=chncmadb;Persist Security Info=True;User ID=chncmadb;Data Source=towebserver" 'Adodc1RecordSource = "T320481TR012004" '表名不能加方括号 Adodc1RecordSource = "select from T320481TR012004" Adodc1Refresh Set DataGrid1DataSource = Adodc1 DataGrid1RefreshEnd Sub 5'ADO控件与SQLserver数据库连接'未测试Private Sub Command5_Click() Adodc1ConnectionString = "Provider=SQLOLEDB1;Password=111;Persist Security Info=True;User ID=111;Initial Catalog=111;Data Source=111" 'Adodc1RecordSource = "T320481TR012004" Adodc1RecordSource = "select from T320481TR012004" Adodc1Refresh Set DataGrid1DataSource = Adodc1 DataGrid1RefreshEnd Sub 四、用ADO代码连接数据库'在使用ADO对象前应选定Visual Basic菜单下的[工程]中的引用了菜单中的[MicrosoftActiveX Data Object 25 Library]选项,或其它版本1'ADO代码与Access2000数据库连接Private Sub Command1_Click() Dim AdoCnn As ADODBConnection Dim AdoRs As ADODBRecordset Set AdoCnn = New ADODBConnection Set AdoRs = New ADODBRecordset AdoCnnCursorLocation = adUseClient 'open后面的字符串可以参考ADO控件连接ConnectionString后面的的字符串 AdoCnnOpen "Provider=MicrosoftJetOLEDB40;Data Source=" & AppPath & "/chncmadb1mdb;Jet OLEDB:DataBase PASSWORD=123456"AdoRsOpen "select from [耕地资源管理单元属性数据表2004]", AdoCnn, adOpenDynamic, adLockPessimistic, adCmdText Set DataGrid1DataSource = AdoRs Set AdoRs = Nothing Set AdoCnn = NothingEnd Sub 2'ADO代码与DBF表连接Private Sub Command2_Click() Dim AdoCnn As ADODBConnection Dim AdoRs As ADODBRecordset Set AdoCnn = New ADODBConnection Set AdoRs = New ADODBRecordset AdoCnnCursorLocation = adUseClient 'open后面的字符串可以参考ADO控件连接ConnectionString后面的的字符串 AdoCnnOpen "Provider=MSDASQL1;Driver=Microsoft Visual Foxpro Driver;SourceDB=" & AppPath & ";SourceType=DBF;Locale Identifier=2052"AdoRsOpen "select from [DBF1]", AdoCnn, adOpenDynamic, adLockPessimistic, adCmdText Set DataGrid1DataSource = AdoRs Set AdoRs = Nothing Set AdoCnn = NothingEnd Sub3'ADO代码与Excel表连接Private Sub Command3_Click() Dim AdoCnn As ADODBConnection Dim AdoRs As ADODBRecordset Set AdoCnn = New ADODBConnection Set AdoRs = New ADODBRecordset AdoCnnCursorLocation = adUseClient 'open后面的字符串可以参考ADO控件连接ConnectionString后面的的字符串 AdoCnnOpen"Provider=MicrosoftJetOLEDB40;Persist Security Info=False;Data Source=" & AppPath & "/EXcelxls;Extended Properties='Excel 80;HDR=Yes'"AdoRsOpen "select from [EXcelxls]", AdoCnn, adOpenDynamic, adLockPessimistic, adCmdText Set DataGrid1DataSource = AdoRs Set AdoRs = Nothing Set AdoCnn = NothingEnd Sub 4'ADO代码与Oracle数据库连接Private Sub Command4_Click() Dim AdoCnn As ADODBConnection Dim AdoRs As ADODBRecordset Set AdoCnn = New ADODBConnection Set AdoRs = New ADODBRecordset AdoCnnCursorLocation = adUseClient 'open后面的字符串可以参考ADO控件连接ConnectionString后面的的字符串 AdoCnnOpen "Provider=OraOLEDBOracle1;Password=chncmadb;Persist Security Info=True;User ID=chncmadb;Data Source=towebserver"AdoRsOpen "select from T320481TR012004", AdoCnn, adOpenDynamic, adLockPessimistic, adCmdText Set DataGrid1DataSource = AdoRs Set AdoRs = Nothing Set AdoCnn = NothingEnd Sub 5'ADO代码与SQLserver数据库连接'未测试Private Sub Command5_Click() Dim AdoCnn As ADODBConnection Dim AdoRs As ADODBRecordset Set AdoCnn = New ADODBConnection Set AdoRs = New ADODBRecordset AdoCnnCursorLocation = adUseClient 'open后面的字符串可以参考ADO控件连接ConnectionString后面的的字符串 AdoCnnOpen "Provider=SQLOLEDB1;Password=111;Persist Security Info=True;User ID=111;Initial Catalog=111;Data Source=111"AdoRsOpen "select from T320481TR012004", AdoCnn, adOpenDynamic, adLockPessimistic, adCmdText Set DataGrid1DataSource = AdoRs Set AdoRs = Nothing Set AdoCnn = NothingEnd Sub
public cnn as adodbconnection
public rs as abodbrecordset
dim count as integer
count = 0
set cnn = new adodbconncetion
set rs = new adodbrecordset
cnnopen"连接数据库语句"
rsopen"select from 表 where 性别 = '" & 男 &"' and 适合部门='" & 销售部门 & "'" ,cnn
do while rseof =false
count=count+1
rsmovenext
loop
rsclose
教程1:李天生老师VB教程
Visual
Basic
60从入门到精通
教程2:30天学通Visual
Basic项目案例开发
视频教程+源码
教程3:VB入门到高级语言开发
VB60
程序设计视频教程
教程4:Visual
Basic范例开发大全Visual
Basic案例光盘压缩包
教程5:用多媒体学Visual
Basic
2008
视频教程
VB
2008视频教程
教程地址:
vbnet数据库学习哪好vbnet数据库在哪所学校可以学习到这门课程。大家有什么好的职业学校推荐给我们
相信每一个学习数据库的人都在寻找合适的vbnet数据库教程学习。但是令人很失望的是,我们没有找到合适的,而且,在我们遇到困难的时候,往往不知道该去找谁来帮助我们,这往往让我们艰难的学习之路走的更加困难。在这里,南邵南邵IT培训诚心为大家推荐IT职业教育学校----南邵北大青鸟学校。
北大青鸟是专业的计算机IT职业教育培训学校,成立于1999年,多年来致力于计算机人才的培养,vbnet数据库是他们的基础课程。其课程是和印度阿波泰克公司合作研究,具有国际水平,其证书更是国内外通用。在同行业中认可度极高。能够得到这里的老师指导,将会是你受益不尽。
vbnet数据库学习哪好vbnet数据库学习,就来南邵北大青鸟学校。
以上就是关于VB如何连接网络数据库全部的内容,包括:VB如何连接网络数据库、vb与access数据库连接有几种方法、VB与各数据库的几种连接方式等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)