This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Dreamweaver > August 2004 > Converting ASP Data Connections to ASP.NET
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Converting ASP Data Connections to ASP.NET
|
|
|
| This is the first time I've tried to convert my .asp ado connection to the
..NET framework and I'm totally lost.
I'm trying to add a new record using the code below and am getting an
error - BC30518: Overload resolution failed because no accessible 'Update'
can be called with these arguments:
Dim cnObj as OleDbConnection = New
OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbPath &
";")
Dim daVisitors As OleDbDataAdapter = New
OleDbDataAdapter("SELECT * From Visitors", cnObj)
Dim dsVisitors As New DataSet()
Dim dtVisitors As DataTable
Dim drVisitors As DataRow
cnObj.Open()
daVisitors.Fill(dsVisitors, "Visitors")
dtVisitors = dsVisitors.Tables("Visitors")
drVisitors = dtVisitors.NewRow()
With drVisitors
.Item("Field1") = "Some Data"
..Item("Field2") = "Some Data 2"
End With
dtVisitors.Rows.Add(drVisitors)
daVisitors.Update(drVisitors)
cnObj.Close
Because I have little experience with ADO.Net Syntax I'm not even sure if
this is the right approach. Any help would be greatly appreciated.
CES
| |
| Paul Whitham TMM 2004-08-03, 4:14 am |
| You code there is a select statement and not an update statement. The code
below is for an update statement
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
objConn = New
OleDbConnection(ConfigurationSettings.AppSettings("DSN"))
objCmd = New OleDbCommand("Insert INTO
tblCourseNames(CourseName,CourseOutline) VALUES (@CourseName,
@CourseOutline)", objConn)
objCmd.Parameters.Add("@CourseName", txtCourseName.Text)
objCmd.Parameters.Add("@CourseOutline", FreeTextBox1.Text)
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()
End Sub
This is a attached to a Button event. The line
objConn = New OleDbConnection(ConfigurationSettings.AppSettings("DSN"))
references the connection string that is stored in the web.config file like
this
<appSettings>
<add key="dsn" value="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\wwwroot\TurtleBay\Database\Schedule.mdb;Persist Security
Info=False" />
</appSettings>
--
Regards
Paul Whitham
Macromedia Certified Professional for Dreamweaver MX2004
Valleybiz Internet Design
www.valleybiz.net
Team Macromedia Volunteer for Ultradev/Dreamweaver MX
www.macromedia.com/support/forums/team_macromedia
"CES" <none@none.com> wrote in message
news:cemov6$neb$1@forums.macromedia.com...
> This is the first time I've tried to convert my .asp ado connection to the
> .NET framework and I'm totally lost.
>
>
>
> I'm trying to add a new record using the code below and am getting an
> error - BC30518: Overload resolution failed because no accessible 'Update'
> can be called with these arguments:
>
>
>
>
>
> Dim cnObj as OleDbConnection = New
> OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbPath &
> ";")
>
> Dim daVisitors As OleDbDataAdapter = New
> OleDbDataAdapter("SELECT * From Visitors", cnObj)
>
> Dim dsVisitors As New DataSet()
>
> Dim dtVisitors As DataTable
>
> Dim drVisitors As DataRow
>
>
>
> cnObj.Open()
>
>
>
> daVisitors.Fill(dsVisitors, "Visitors")
>
> dtVisitors = dsVisitors.Tables("Visitors")
>
> drVisitors = dtVisitors.NewRow()
>
> With drVisitors
>
> .Item("Field1") = "Some Data"
>
> .Item("Field2") = "Some Data 2"
>
> End With
>
> dtVisitors.Rows.Add(drVisitors)
>
> daVisitors.Update(drVisitors)
>
>
>
>
>
> cnObj.Close
>
>
>
> Because I have little experience with ADO.Net Syntax I'm not even sure if
> this is the right approach. Any help would be greatly appreciated.
>
> CES
>
>
| |
|
| Paul,
Are you accessing a query with in the access Database or are you accessing a
Table? I ask becouse I'm geting the following error:
---- Exception Details: System.Data.OleDb.OleDbException: Operation must use
an updateable query. ----
If you are going against a Query as I suspect do you know how I would modify
your code to allow updating a table???
Thanks
CES
Dim objConn As OleDbConnection = New
OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbPath &
";")
Dim objCmd As OleDbCommand = New OleDbCommand("Insert INTO
visitors(UserNum,BrowserId) VALUES (@UserNum,@BrowserId)", objConn)
objCmd.Parameters.Add("@UserNum", "userNum text")
objCmd.Parameters.Add("@BrowserId", "BrowserId Text")
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()
"Paul Whitham TMM" <paul@valleybiz.net> wrote in message
news:cemsml$qpt$1@forums.macromedia.com...
> You code there is a select statement and not an update statement. The code
> below is for an update statement
>
> Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnAdd.Click
> Dim objConn As OleDbConnection
> Dim objCmd As OleDbCommand
> objConn = New
> OleDbConnection(ConfigurationSettings.AppSettings("DSN"))
> objCmd = New OleDbCommand("Insert INTO
> tblCourseNames(CourseName,CourseOutline) VALUES (@CourseName,
> @CourseOutline)", objConn)
> objCmd.Parameters.Add("@CourseName", txtCourseName.Text)
> objCmd.Parameters.Add("@CourseOutline", FreeTextBox1.Text)
> objConn.Open()
> objCmd.ExecuteNonQuery()
> objConn.Close()
> End Sub
>
> This is a attached to a Button event. The line
> objConn = New OleDbConnection(ConfigurationSettings.AppSettings("DSN"))
>
> references the connection string that is stored in the web.config file
like
> this
>
> <appSettings>
> <add key="dsn" value="Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=C:\Inetpub\wwwroot\TurtleBay\Database\Schedule.mdb;Persist Security
> Info=False" />
>
> </appSettings>
>
>
> --
> Regards
>
> Paul Whitham
> Macromedia Certified Professional for Dreamweaver MX2004
> Valleybiz Internet Design
> www.valleybiz.net
>
> Team Macromedia Volunteer for Ultradev/Dreamweaver MX
> www.macromedia.com/support/forums/team_macromedia
>
> "CES" <none@none.com> wrote in message
> news:cemov6$neb$1@forums.macromedia.com...
the[color=darkred]
'Update'[color=darkred]
&[color=darkred]
if[color=darkred]
>
>
| |
| Paul Whitham TMM 2004-08-03, 4:14 am |
| I am accessing a table. The error you are getting is because the database,
or the folder it is sitting in, does not have write access enabled for the
anonymous .net web client.
If this is on a shared host, ask you tech people to correct. If it is on a
local machine follow the steps in this tutorial
http://www.charon.co.uk/content.asp...27&ArticleID=56
--
Regards
Paul Whitham
Macromedia Certified Professional for Dreamweaver MX2004
Valleybiz Internet Design
www.valleybiz.net
Team Macromedia Volunteer for Ultradev/Dreamweaver MX
www.macromedia.com/support/forums/team_macromedia
"CES" <none@none.com> wrote in message
news:cemvkg$88$1@forums.macromedia.com...
> Paul,
>
> Are you accessing a query with in the access Database or are you accessing
a
> Table? I ask becouse I'm geting the following error:
>
> ---- Exception Details: System.Data.OleDb.OleDbException: Operation must
use
> an updateable query. ----
>
> If you are going against a Query as I suspect do you know how I would
modify
> your code to allow updating a table???
>
> Thanks
> CES
>
> Dim objConn As OleDbConnection = New
> OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbPath &
> ";")
> Dim objCmd As OleDbCommand = New OleDbCommand("Insert INTO
> visitors(UserNum,BrowserId) VALUES (@UserNum,@BrowserId)", objConn)
> objCmd.Parameters.Add("@UserNum", "userNum text")
> objCmd.Parameters.Add("@BrowserId", "BrowserId Text")
> objConn.Open()
> objCmd.ExecuteNonQuery()
> objConn.Close()
>
>
> "Paul Whitham TMM" <paul@valleybiz.net> wrote in message
> news:cemsml$qpt$1@forums.macromedia.com...
code[color=darkred]
> like
Security[color=darkred]
> the
> 'Update'
dbPath[color=darkred]
> &
> if
>
>
| |
|
| Thank You Paul, while i had permisions for the IUSR account I didn't for the
ASPNET Account.
CES
"Paul Whitham TMM" <paul@valleybiz.net> wrote in message
news:cen1qk$28a$1@forums.macromedia.com...
> I am accessing a table. The error you are getting is because the database,
> or the folder it is sitting in, does not have write access enabled for the
> anonymous .net web client.
>
> If this is on a shared host, ask you tech people to correct. If it is on a
> local machine follow the steps in this tutorial
> http://www.charon.co.uk/content.asp...27&ArticleID=56
>
> --
> Regards
>
> Paul Whitham
> Macromedia Certified Professional for Dreamweaver MX2004
> Valleybiz Internet Design
> www.valleybiz.net
>
> Team Macromedia Volunteer for Ultradev/Dreamweaver MX
> www.macromedia.com/support/forums/team_macromedia
>
> "CES" <none@none.com> wrote in message
> news:cemvkg$88$1@forums.macromedia.com...
accessing[color=darkred]
> a
> use
> modify
&[color=darkred]
> code
OleDbConnection(ConfigurationSettings.AppSettings("DSN"))[color=darkred]
> Security
to[color=darkred]
an[color=darkred]
> dbPath
sure[color=darkred]
>
>
| |
|
| Paul,
How do you deal with null Values
Like
if request("UserNum") <> "" Then
objCmd.Parameters.Add("@UserNum", "userNum text")
End If
Thanks
CES
"Paul Whitham TMM" <paul@valleybiz.net> wrote in message
news:cen1qk$28a$1@forums.macromedia.com...
> I am accessing a table. The error you are getting is because the database,
> or the folder it is sitting in, does not have write access enabled for the
> anonymous .net web client.
>
> If this is on a shared host, ask you tech people to correct. If it is on a
> local machine follow the steps in this tutorial
> http://www.charon.co.uk/content.asp...27&ArticleID=56
>
> --
> Regards
>
> Paul Whitham
> Macromedia Certified Professional for Dreamweaver MX2004
> Valleybiz Internet Design
> www.valleybiz.net
>
> Team Macromedia Volunteer for Ultradev/Dreamweaver MX
> www.macromedia.com/support/forums/team_macromedia
>
> "CES" <none@none.com> wrote in message
> news:cemvkg$88$1@forums.macromedia.com...
accessing[color=darkred]
> a
> use
> modify
&[color=darkred]
> code
OleDbConnection(ConfigurationSettings.AppSettings("DSN"))[color=darkred]
> Security
to[color=darkred]
an[color=darkred]
> dbPath
sure[color=darkred]
>
>
| |
| Paul Whitham TMM 2004-08-03, 11:14 pm |
| Firstly if the field is not supposed to be blank that use validation of the
form to stop the process, and surround you update statement with
if (page.isValid) then
--
Regards
Paul Whitham
Macromedia Certified Professional for Dreamweaver MX2004
Valleybiz Internet Design
www.valleybiz.net
Team Macromedia Volunteer for Ultradev/Dreamweaver MX
www.macromedia.com/support/forums/team_macromedia
"CES" <none@none.com> wrote in message
news:cencjp$c1g$1@forums.macromedia.com...
> Paul,
> How do you deal with null Values
> Like
> if request("UserNum") <> "" Then
> objCmd.Parameters.Add("@UserNum", "userNum text")
> End If
>
> Thanks
> CES
>
> "Paul Whitham TMM" <paul@valleybiz.net> wrote in message
> news:cen1qk$28a$1@forums.macromedia.com...
database,[color=darkred]
the[color=darkred]
a[color=darkred]
> accessing
must[color=darkred]
dbPath[color=darkred]
> &
The[color=darkred]
> OleDbConnection(ConfigurationSettings.AppSettings("DSN"))
file[color=darkred]
connection[color=darkred]
> to
> an
> sure
>
>
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|