Home All Groups Group Topic Archive Search About

Detailsview updading issue

Author
16 Jun 2009 9:19 AM
Peter
HI

I currently use an access db as my datasource and use the following to bind
my data into my DetailsView below

Page_Load()
...
   myDetailsView.DataSource = myOleDbCommand.ExecuteReader();
   myDetailsView.DataBind();

<Body>
...
  <asp:DetailsView ID="myDetailsView" runat="server"
AutoGenerateRows="False">
  <asp:BoundField DataField="FieldA" headertext="FieldA"
SortExpression="FieldA" />
  <asp:BoundField DataField="FieldB" headertext="FieldB"
SortExpression="FieldB" />
...

How would I configure my event handler to have my dataview goes into Edit
mode and update my binded records into my access db ?

Thanks
Peter

Author
16 Jun 2009 10:36 AM
Peter
I managed to give up the data binding method and switch to using
<AccessDataSource>

Show quoteHide quote
"Peter" <peter***@msn.com> wrote in message
news:eqiqWOm7JHA.1712@TK2MSFTNGP03.phx.gbl...
> HI
>
> I currently use an access db as my datasource and use the following to
> bind my data into my DetailsView below
>
> Page_Load()
> ..
>   myDetailsView.DataSource = myOleDbCommand.ExecuteReader();
>   myDetailsView.DataBind();
>
> <Body>
> ..
>  <asp:DetailsView ID="myDetailsView" runat="server"
> AutoGenerateRows="False">
>  <asp:BoundField DataField="FieldA" headertext="FieldA"
> SortExpression="FieldA" />
>  <asp:BoundField DataField="FieldB" headertext="FieldB"
> SortExpression="FieldB" />
> ..
>
> How would I configure my event handler to have my dataview goes into Edit
> mode and update my binded records into my access db ?
>
> Thanks
> Peter
>
>
>
Are all your drivers up to date? click for free checkup

Author
16 Jun 2009 1:47 PM
Gregory A. Beamer
Show quote Hide quote
"Peter" <peter***@msn.com> wrote in
news:eqiqWOm7JHA.1712@TK2MSFTNGP03.phx.gbl:

> HI
>
> I currently use an access db as my datasource and use the following to
> bind my data into my DetailsView below
>
> Page_Load()
> ..
>    myDetailsView.DataSource = myOleDbCommand.ExecuteReader();
>    myDetailsView.DataBind();
>
> <Body>
> ..
>   <asp:DetailsView ID="myDetailsView" runat="server"
> AutoGenerateRows="False">
>   <asp:BoundField DataField="FieldA" headertext="FieldA"
> SortExpression="FieldA" />
>   <asp:BoundField DataField="FieldB" headertext="FieldB"
> SortExpression="FieldB" />
> ..
>
> How would I configure my event handler to have my dataview goes into
> Edit mode and update my binded records into my access db ?


First, have the Page_Load call a routine. Standard is this:

Proected Sub Page_Load(sender as Object, e as EventArgs)
     _Handles Page.Load

    If Not Page.IsPostBack() Then
        BindPage()
    End If

End Sub

Protected Sub BindPage()

    ...

    myDetailsView.DataSource = myOleDbCommand.ExecuteReader();
    myDetailsView.DataBind()
End Sub

This allows you to call the row on the events that will change content
of the data grid. You then call the same on the events that add, update
and delete rows.

When you use the automagic wiring bits, you may have to wire up some
events. I know RowsAdded and RowsRemoved can be used. I am not sure
about edit off hand, but I generally will edit using a DetailsView (user
clicks on row and it goes to Details View), as it focus the user on the
row rather than editing like a spreadsheet.It has the following events
to handle:

ItemDeleted
ItemInserted
ItemUpdated

You can also use ItemDeleting if you want to stop a person from deleting
certain information. Just set e.Cancel to true to stop the action during
this event.

Hope this helps!


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
Show quoteHide quote
|      Think outside the box!             |
*******************************************
Author
16 Jun 2009 5:29 PM
Peter
Thanks Gregory but I decided to use the DetailsView for editing my records and everything works perfectly with the following.

---
            <asp:AccessDataSource ID="myProductTable" runat="Server" DataFile="/abc.mdb" SelectCommand="SELECT * FROM table1"
UpdateCommand="UPDATE table1 SET name = @name WHERE username = @username"
                DeleteCommand="DELETE FROM table1 WHERE (username = @username)" InsertCommand="INSERT INTO table1(username, name)
VALUES (@username, @name)">
---

But when I want to leave out the "DataFile" property and dynamically assign it in my page_load  module.  It works good when in the
ReadOnly mode and also allows me to click Edit and New link button, but it seems cannot works for Update, Delete and Insert.  The
following exception happen when I click the "Update", "Delete" and "Insert" button.

---
System.Data.OleDb.OleDbException: No error message available, result code: DB_SEC_E_AUTH_FAILED(0x80040E4D).
---

Can you give me a hand on how I can dynamically assign the DataFile property to work perfectly ?

Thanks
Peter

Show quoteHide quote
"Gregory A. Beamer" <NoSpamMgbworld@comcast.netNoSpamM> wrote in message news:Xns9C2C597214203gbworld@207.46.248.16...
> "Peter" <peter***@msn.com> wrote in
> news:eqiqWOm7JHA.1712@TK2MSFTNGP03.phx.gbl:
>
>> HI
>>
>> I currently use an access db as my datasource and use the following to
>> bind my data into my DetailsView below
>>
>> Page_Load()
>> ..
>>    myDetailsView.DataSource = myOleDbCommand.ExecuteReader();
>>    myDetailsView.DataBind();
>>
>> <Body>
>> ..
>>   <asp:DetailsView ID="myDetailsView" runat="server"
>> AutoGenerateRows="False">
>>   <asp:BoundField DataField="FieldA" headertext="FieldA"
>> SortExpression="FieldA" />
>>   <asp:BoundField DataField="FieldB" headertext="FieldB"
>> SortExpression="FieldB" />
>> ..
>>
>> How would I configure my event handler to have my dataview goes into
>> Edit mode and update my binded records into my access db ?
>
>
> First, have the Page_Load call a routine. Standard is this:
>
> Proected Sub Page_Load(sender as Object, e as EventArgs)
>     _Handles Page.Load
>
>    If Not Page.IsPostBack() Then
>        BindPage()
>    End If
>
> End Sub
>
> Protected Sub BindPage()
>
>    ...
>
>    myDetailsView.DataSource = myOleDbCommand.ExecuteReader();
>    myDetailsView.DataBind()
> End Sub
>
> This allows you to call the row on the events that will change content
> of the data grid. You then call the same on the events that add, update
> and delete rows.
>
> When you use the automagic wiring bits, you may have to wire up some
> events. I know RowsAdded and RowsRemoved can be used. I am not sure
> about edit off hand, but I generally will edit using a DetailsView (user
> clicks on row and it goes to Details View), as it focus the user on the
> row rather than editing like a spreadsheet.It has the following events
> to handle:
>
> ItemDeleted
> ItemInserted
> ItemUpdated
>
> You can also use ItemDeleting if you want to stop a person from deleting
> certain information. Just set e.Cancel to true to stop the action during
> this event.
>
> Hope this helps!
>
>
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>
> Twitter: @gbworld
> Blog: http://gregorybeamer.spaces.live.com
>
> *******************************************
> |      Think outside the box!             |
> *******************************************
Author
16 Jun 2009 5:32 PM
Peter
Also, can I do any validation on the field values before it's being updated to avoid data type mismatch on any fields ?

Show quoteHide quote
"Peter" <peter***@msn.com> wrote in message news:egwbCgq7JHA.3304@TK2MSFTNGP06.phx.gbl...
> Thanks Gregory but I decided to use the DetailsView for editing my records and everything works perfectly with the following.
>
> ---
>            <asp:AccessDataSource ID="myProductTable" runat="Server" DataFile="/abc.mdb" SelectCommand="SELECT * FROM table1"
> UpdateCommand="UPDATE table1 SET name = @name WHERE username = @username"
>                DeleteCommand="DELETE FROM table1 WHERE (username = @username)" InsertCommand="INSERT INTO table1(username, name)
> VALUES (@username, @name)">
> ---
>
> But when I want to leave out the "DataFile" property and dynamically assign it in my page_load  module.  It works good when in the
> ReadOnly mode and also allows me to click Edit and New link button, but it seems cannot works for Update, Delete and Insert.  The
> following exception happen when I click the "Update", "Delete" and "Insert" button.
>
> ---
> System.Data.OleDb.OleDbException: No error message available, result code: DB_SEC_E_AUTH_FAILED(0x80040E4D).
> ---
>
> Can you give me a hand on how I can dynamically assign the DataFile property to work perfectly ?
>
> Thanks
> Peter
>
> "Gregory A. Beamer" <NoSpamMgbworld@comcast.netNoSpamM> wrote in message news:Xns9C2C597214203gbworld@207.46.248.16...
>> "Peter" <peter***@msn.com> wrote in
>> news:eqiqWOm7JHA.1712@TK2MSFTNGP03.phx.gbl:
>>
>>> HI
>>>
>>> I currently use an access db as my datasource and use the following to
>>> bind my data into my DetailsView below
>>>
>>> Page_Load()
>>> ..
>>>    myDetailsView.DataSource = myOleDbCommand.ExecuteReader();
>>>    myDetailsView.DataBind();
>>>
>>> <Body>
>>> ..
>>>   <asp:DetailsView ID="myDetailsView" runat="server"
>>> AutoGenerateRows="False">
>>>   <asp:BoundField DataField="FieldA" headertext="FieldA"
>>> SortExpression="FieldA" />
>>>   <asp:BoundField DataField="FieldB" headertext="FieldB"
>>> SortExpression="FieldB" />
>>> ..
>>>
>>> How would I configure my event handler to have my dataview goes into
>>> Edit mode and update my binded records into my access db ?
>>
>>
>> First, have the Page_Load call a routine. Standard is this:
>>
>> Proected Sub Page_Load(sender as Object, e as EventArgs)
>>     _Handles Page.Load
>>
>>    If Not Page.IsPostBack() Then
>>        BindPage()
>>    End If
>>
>> End Sub
>>
>> Protected Sub BindPage()
>>
>>    ...
>>
>>    myDetailsView.DataSource = myOleDbCommand.ExecuteReader();
>>    myDetailsView.DataBind()
>> End Sub
>>
>> This allows you to call the row on the events that will change content
>> of the data grid. You then call the same on the events that add, update
>> and delete rows.
>>
>> When you use the automagic wiring bits, you may have to wire up some
>> events. I know RowsAdded and RowsRemoved can be used. I am not sure
>> about edit off hand, but I generally will edit using a DetailsView (user
>> clicks on row and it goes to Details View), as it focus the user on the
>> row rather than editing like a spreadsheet.It has the following events
>> to handle:
>>
>> ItemDeleted
>> ItemInserted
>> ItemUpdated
>>
>> You can also use ItemDeleting if you want to stop a person from deleting
>> certain information. Just set e.Cancel to true to stop the action during
>> this event.
>>
>> Hope this helps!
>>
>>
>> --
>> Gregory A. Beamer
>> MVP; MCP: +I, SE, SD, DBA
>>
>> Twitter: @gbworld
>> Blog: http://gregorybeamer.spaces.live.com
>>
>> *******************************************
>> |      Think outside the box!             |
>> *******************************************
>
>
Author
16 Jun 2009 6:52 PM
Gregory A. Beamer
Show quote Hide quote
"Peter" <peter***@msn.com> wrote in
news:egwbCgq7JHA.3304@TK2MSFTNGP06.phx.gbl:

> Thanks Gregory but I decided to use the DetailsView for editing my
> records and everything works perfectly with the following.
>
> ---
>             <asp:AccessDataSource ID="myProductTable" runat="Server"
>             DataFile="/abc.mdb" SelectCommand="SELECT * FROM table1"
> UpdateCommand="UPDATE table1 SET name = @name WHERE username =
> @username"
>                 DeleteCommand="DELETE FROM table1 WHERE (username =
>                 @username)" InsertCommand="INSERT INTO
>                 table1(username, name)
> VALUES (@username, @name)">
> ---
>
> But when I want to leave out the "DataFile" property and dynamically
> assign it in my page_load  module.  It works good when in the ReadOnly
> mode and also allows me to click Edit and New link button, but it
> seems cannot works for Update, Delete and Insert.  The following
> exception happen when I click the "Update", "Delete" and "Insert"
> button.
>
> ---
> System.Data.OleDb.OleDbException: No error message available, result
> code: DB_SEC_E_AUTH_FAILED(0x80040E4D). ---
>
> Can you give me a hand on how I can dynamically assign the DataFile
> property to work perfectly ?


Any time you step outside of the box, you can get burned by MS.

Most likely you are missing some quote mark or you are using an @ and the
string is not being properly translated.

One way around this is to always set the connection string explicitly. As I
do not work with the DataSource objects very often, I am not sure where to
look for an answer to the question. I will have to look that one up later.

As for validation, you are probably best to do validation on the server
side and attach the validation to the events ending in -ing. For example
ItemUpdating instead of ItemUpdated. This allows you to set e.Cancel to
true when it fails validation. The basic pattern is:

If Not (Validated()) Then
    e.Cancel = True
End If

i will see if I can find anything for the DataSource objects on conneciton
string.


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
Show quoteHide quote
|      Think outside the box!             |
*******************************************
Author
17 Jun 2009 1:30 AM
Peter
Hi Gregory

Thanks for your help..   Referring to my error when updating the access
database file, it defintely something with the DataFile assignment and I am
not sure WHERE I should re-assign the .DataFile property.   The first time
it was assigned it works perfectly for displaying the record for the first
time but not when performing any updating.   If I include the
"DataFile="/abc.mdb" in the AccessDataSource line, everything works
perfectly.  Any ideas ?

I will play around with the ItemUpdating event and see ....thanks :)

Peter



Show quoteHide quote
"Gregory A. Beamer" <NoSpamMgbworld@comcast.netNoSpamM> wrote in message
news:Xns9C2C8D12273A2gbworld@207.46.248.16...
> "Peter" <peter***@msn.com> wrote in
> news:egwbCgq7JHA.3304@TK2MSFTNGP06.phx.gbl:
>
>> Thanks Gregory but I decided to use the DetailsView for editing my
>> records and everything works perfectly with the following.
>>
>> ---
>>             <asp:AccessDataSource ID="myProductTable" runat="Server"
>>             DataFile="/abc.mdb" SelectCommand="SELECT * FROM table1"
>> UpdateCommand="UPDATE table1 SET name = @name WHERE username =
>> @username"
>>                 DeleteCommand="DELETE FROM table1 WHERE (username =
>>                 @username)" InsertCommand="INSERT INTO
>>                 table1(username, name)
>> VALUES (@username, @name)">
>> ---
>>
>> But when I want to leave out the "DataFile" property and dynamically
>> assign it in my page_load  module.  It works good when in the ReadOnly
>> mode and also allows me to click Edit and New link button, but it
>> seems cannot works for Update, Delete and Insert.  The following
>> exception happen when I click the "Update", "Delete" and "Insert"
>> button.
>>
>> ---
>> System.Data.OleDb.OleDbException: No error message available, result
>> code: DB_SEC_E_AUTH_FAILED(0x80040E4D). ---
>>
>> Can you give me a hand on how I can dynamically assign the DataFile
>> property to work perfectly ?
>
>
> Any time you step outside of the box, you can get burned by MS.
>
> Most likely you are missing some quote mark or you are using an @ and the
> string is not being properly translated.
>
> One way around this is to always set the connection string explicitly. As
> I
> do not work with the DataSource objects very often, I am not sure where to
> look for an answer to the question. I will have to look that one up later.
>
> As for validation, you are probably best to do validation on the server
> side and attach the validation to the events ending in -ing. For example
> ItemUpdating instead of ItemUpdated. This allows you to set e.Cancel to
> true when it fails validation. The basic pattern is:
>
> If Not (Validated()) Then
>    e.Cancel = True
> End If
>
> i will see if I can find anything for the DataSource objects on conneciton
> string.
>
>
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>
> Twitter: @gbworld
> Blog: http://gregorybeamer.spaces.live.com
>
> *******************************************
> |      Think outside the box!             |
> *******************************************
Author
17 Jun 2009 5:39 PM
Gregory A. Beamer
Show quote Hide quote
"Peter" <peter***@msn.com> wrote in
news:u1mOqsu7JHA.1564@TK2MSFTNGP06.phx.gbl:

> Hi Gregory
>
> Thanks for your help..   Referring to my error when updating the
> access database file, it defintely something with the DataFile
> assignment and I am not sure WHERE I should re-assign the .DataFile
> property.   The first time it was assigned it works perfectly for
> displaying the record for the first time but not when performing any
> updating.   If I include the "DataFile="/abc.mdb" in the
> AccessDataSource line, everything works perfectly.  Any ideas ?
>
> I will play around with the ItemUpdating event and see ....thanks :)


Access is known to be problematic when deployed. If you are always explicit
on file location, it is less problematic.

If you have the option of moving to SQL Express, I would go that route over
Access, as Access has too many limitations for web use. That is, at least,
my opinion on the matter.


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
Show quoteHide quote
|      Think outside the box!             |
*******************************************

Bookmark and Share