ADOConnection ?

  • Thread starter Thread starter shimmer
  • Start date Start date
S

shimmer

Hi.
i have a code as below. When i define ADOCommand as well as
ADOConnection, they do not work but i have already defined
<%@Import Namespace=System.Data.ADO%>
<%@Import Namespace=System.Data%>

Can anyone help me? Thank you

Code:

<%@Import Namespace=System.Data%>
<%@Import Namespace=System.Data.ADO%>

<Html>
<Form id="F1" Runat="Server">
Enter Query: <Input Type="Text" Id="Text1" Runat="Server" >
<Button ID="Button1" Runat="Server"
OnServerClick="Button1_Click">
Execute
</Button>
</form>
<Span ID="Sp1" Runat="Server"/>


<Script Language="VB" Runat="Server">
Sub Button1_Click(sender As Object, E As EventArgs)
Dim cnA As ADOConnection=New ADOConnection
Dim cmA As ADOCommand=New ADOCommand
cnA.Provider="Microsoft.Jet.OLEDB.4.0"
cnA.DataSource="C:\MyWeb.mdb"
cnA.UserID="Admin"
cnA.Open()
cmA.ActiveConnection=cnA
cmA.CommandType=CommandType.Text
cmA.CommandText=Text1.Value
cmA.Execute()
Sp1.InnerText="This will affect" & cmA.RecordsAffected & "
....."
End Sub
</SCRIPT>
</Html>
 
Why are you using ADO rather than ADO.NET?


shimmer said:
Hi.
i have a code as below. When i define ADOCommand as well as
ADOConnection, they do not work but i have already defined
<%@Import Namespace=System.Data.ADO%>
<%@Import Namespace=System.Data%>

Can anyone help me? Thank you

Code:

<%@Import Namespace=System.Data%>
<%@Import Namespace=System.Data.ADO%>

<Html>
<Form id="F1" Runat="Server">
Enter Query: <Input Type="Text" Id="Text1" Runat="Server" >
<Button ID="Button1" Runat="Server"
OnServerClick="Button1_Click">
Execute
</Button>
</form>
<Span ID="Sp1" Runat="Server"/>


<Script Language="VB" Runat="Server">
Sub Button1_Click(sender As Object, E As EventArgs)
Dim cnA As ADOConnection=New ADOConnection
Dim cmA As ADOCommand=New ADOCommand
cnA.Provider="Microsoft.Jet.OLEDB.4.0"
cnA.DataSource="C:\MyWeb.mdb"
cnA.UserID="Admin"
cnA.Open()
cmA.ActiveConnection=cnA
cmA.CommandType=CommandType.Text
cmA.CommandText=Text1.Value
cmA.Execute()
Sp1.InnerText="This will affect" & cmA.RecordsAffected & "
...."
End Sub
</SCRIPT>
</Html>
 
The code to connect, query the DB and store results should look like this:

Imports System.OleDB

Dim conStr as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath(relative path to "tracking.mdb")

Dim con as New OleDBConnection(conStr)
Dim da As New OleDbDataAdapter("Select something from something", con)

Dim ds As New DataSet()

Try
con.open()
da.Fill(ds)
Catch eDB As OleDbException
'Assuming you have a label on the form named "lblError"
lblError.Text = eDB.Message
Catch e As Exception
lblError.Text = e.getType.ToString() & " " & e.Message
Finally
con.Close()
End Try


You can also use a dedicated command object (OleDBCommand) and use its
various methods if you only want to get the number of records affected.

You should begin to look at help on ADO.NET.


shimmer said:
How do i use ADO.net then??
 
Back
Top