Access | data | database | problem | Learning Error One: The following error occurred while running the code:
-------------------------------------------------------------------
Compiler error message: BC30002: undefined type ' adoconnection '.
SOURCE Error:
Line one: <script language= "VB" runat= "Server" >
Row 12:sub button1_click (sender as Object, E as EventArgs)
Row 13:dim CnA as Adoconnection=new adoconnection
Line 14:dim CmA as Adocommand=new Adocommand
Line 15:cna.provider= "Microsoft.Jet.OLEDB.4.0"
Source file: G:\inetpub\wwwroot\WebApplication1\WebForm3.aspx line: 13
-----------------------------------------------------------------------------
This is because namespace wrong!
Use the following:
<%@ import namespace= "System.Data"%>
<%@ import namespace= "System.data.Oledb"%>
The corresponding variable is declared as:
Dim myconn As OleDbConnection
Dim mycommand As OleDbCommand
<%@ import namespace= "System.Data"%>
<%@ import namespace= "System.data.SqlClient"%>
The corresponding variable is declared as:
Dim myconn As SqlConnection
Dim mycommand As SqlCommand
<%@ import namespace= "System.Data"%>
<%@ import namespace= "System.data.ODBC"%>
The corresponding variable is declared as:
Dim myconn As OdbcConnection
Dim mycommand As OdbcCommand
The test procedures are as follows:
=============================
<%@ import namespace= "System.Data"%>
<%@ import namespace= "System.data.Oledb"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<BODY>
<script language= "VB" runat= "Server" >
Sub Page_Load (Sender as Object, E as EventArgs)
Dim ds As DataSet
Dim myconn As OleDbConnection
Dim mycommand As OleDbCommand
Myconn=new OleDbConnection ("Provider=sqloledb; Data source= (local); Uid=sa; Pwd=pssword; Initial catalog=database ")
MyConn.Open ()
Mycommand=new OleDbCommand ("SELECT * from User_info", myconn)
Dim myreader as OleDbDataReader = Mycommand.executereader (commandbehavior.closeconnection)
DataGrid1.DataSource =myreader
Datagrid1.databind ()
End Sub
</script>
<P>
<meta content= "Microsoft Visual Studio. NET 7.1" name= "generator" >
<font face= "Song Body" >
<asp:datagrid id= "DATAGRID1" runat= "Server" ></asp:datagrid></FONT>
<meta content= "Visual Basic. NET 7.1" name= "Code_language" >
<meta content= "JavaScript" name= "vs_defaultClientScript" >
<meta content= "http://schemas.microsoft.com/intellisense/ie5" name= "Vs_targetschema" >
</P>
</BODY>
</HTML>
==============================
<%@ import namespace= "System.Data"%>
<%@ import namespace= "System.data.SqlClient"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<BODY>
<script language= "VB" runat= "Server" >
Sub Page_Load (Sender as Object, E as EventArgs)
Dim ds As DataSet
Dim myconn As SqlConnection
Dim mycommand As SqlCommand
Myconn=new SqlConnection ("server=" (local); Uid=sa; Pwd=huangfeng;database=jxjyzb ")
MyConn.Open ()
Mycommand=new Sqlcommand ("SELECT * from User_info", myconn)
Dim myreader As SqlDataReader = Mycommand.executereader (C
[1] [2] [3] Next page