473,769 Members | 5,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DetailsView: InsertMethod not function [ObjectDataSourc e]

I am using DetailsView using ObjectDataSourc e with DataSourceTypeN ame
assigned to the specific class.
SelectMethod, UpdateMethod and DeleteMethod is working successfully, except
InsertMethod.
The error msg returned is: Cannot insert the employee.
With tracing trigger on, I had discovered that the parameter is actually
empty.
The data entered is not pass into the parameter at all !!!
What could be the possible reason?

Below is the setting in my profile.aspx:
<asp:ObjectData Source ID="EmployeeDet ailsObjectDataS ource" runat="server"
OldValuesParame terFormatString ="original_{ 0}"
MaximumRowsPara meterName="" StartRowIndexPa rameterName=""
DataObjectTypeN ame="HRPortal.D ataAccess.HREmp loyee"
TypeName="HRPor tal.DataAccess. EmployeeDAL">
</asp:ObjectDataS ource>

This is how I assign the InsertMethod in my profile.aspx.vb :
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArg s)
Handles Me.Init
EmployeeDetails ObjectDataSourc e.InsertMethod = "InsertEmployee "
End Sub

This is the InsertMethod in my business logic layer,
HRPortal.DataAc cess.EmployeeDA L.vb:
Public Shared Function InsertEmployee( ByVal employee As HREmployee) As Integer
If employee.homeAd dress Is Nothing Then employee.homeAd dress = String.Empty
If employee.userNa me Is Nothing Then employee.userNa me = String.Empty
If employee.birthD ay.Equals(DBNul l.Value) Then employee.birthD ay =
DateTime.MinVal ue

Dim sqlCmd1 As String = "SELECT [EmployeeID] FROM [EmployeeMaster] " & _
" WHERE [EmployeeID]=@EmployeeID"
Dim sqlCmd2 As String = "INSERT INTO [EmployeeMaster] " & _
" ([EmployeeID],[EmployeeName], [UserName], [HomeAddress],
[Birthday]) " & _
" Values(@Employe eID, @EmployeeName, @UserName, @HomeAddress,
@Birthday) "
sqlCmd2 = "INSERT INTO [EmployeeMaster] " & _
" ([EmployeeID],[EmployeeName], [UserName], [HomeAddress]) " & _
" Values(@Employe eID, @EmployeeName, @UserName, @HomeAddress) "
Dim conn_MS As SqlConnection = New SqlConnection(_ connectionStrin g)
Dim da_MS As SqlDataAdapter
Dim ds As DataSet = New DataSet()

Dim result As Integer = 0
Try
da_MS = New SqlDataAdapter( sqlCmd1, conn_MS)
da_MS.SelectCom mand.Parameters .Add("@Employee ID",
SqlDbType.VarCh ar, 14).Value = employee.Employ eeID
Dim cmd_MS As SqlCommand = New SqlCommand(sqlC md2, conn_MS)
cmd_MS.Paramete rs.Add("@Employ eeID", SqlDbType.VarCh ar, 14).Value
= employee.Employ eeID
cmd_MS.Paramete rs.Add("@Employ eeName", SqlDbType.VarCh ar,
80).Value = employee.Employ eeName
cmd_MS.Paramete rs.Add("@UserNa me", SqlDbType.VarCh ar, 20).Value =
employee.userNa me
cmd_MS.Paramete rs.Add("@HomeAd dress", SqlDbType.VarCh ar,
200).Value = employee.homeAd dress
'cmd_MS.Paramet ers.Add("@Birth day", SqlDbType.DateT ime).Value =
employee.birthD ay

conn_MS.Open()

da_MS.Fill(ds, "EmployeeMaster ")
If ds.Tables("Empl oyeeMaster").Ro ws.Count = 0 Then
result = cmd_MS.ExecuteN onQuery()
Else
result = -1
End If
Catch ex As SqlException
Throw New Exception("Cann ot insert the employee." + ex.Message + "
" + ex.LineNumber.T oString() + " " + ex.Source + " " + ex.State.ToStri ng())
Finally
conn_MS.Close()
End Try
Return result
End Function

Jan 4 '06 #1
3 2428
>I am using DetailsView using ObjectDataSourc e with DataSourceTypeN ame
assigned to the specific class.


how do you pass that "employee" parameter from the DetailsView to the
ObjectDataSourc e's InsertEmployee method? my guess is that you do not
provide it at all or provide it incorrectly.

Wiktor Zychla

Jan 4 '06 #2
In the Profile.aspx, I had defined a ObjectDataSourc e with the following:
<asp:ObjectData Source ID="EmployeeDet ailsObjectDataS ource" runat="server"
OldValuesParame terFormatString ="original_{ 0}"
MaximumRowsPara meterName="" StartRowIndexPa rameterName=""
DataObjectTypeN ame="HRPortal.D ataAccess.HREmp loyee"
TypeName="HRPor tal.DataAccess. EmployeeDAL">
</asp:ObjectDataS ource>
DataObjectTypeN ame tag is set to an active class, stored in
HRPortal.DataAc cess.HREmployee .vb.

The web form is capable to perform update and delete functions, except
insert function.
I had raised events for both DetailsView_Ite mInserting and
EmployeeDetails ObjectDataSourc e_Inserting. The end result is: empty. The
contents of inputParameter are blank. None of the data entered is pass in.
Thus, when my BLL HRPortal.DataAc cess.EmployeeDA L's InsertEmployee function
receive the InputParameter, aka employee, it fails to add the record.

Regards
"Wiktor Zychla [C# MVP]" wrote:
I am using DetailsView using ObjectDataSourc e with DataSourceTypeN ame
assigned to the specific class.


how do you pass that "employee" parameter from the DetailsView to the
ObjectDataSourc e's InsertEmployee method? my guess is that you do not
provide it at all or provide it incorrectly.

Wiktor Zychla

Jan 5 '06 #3
> I had raised events for both DetailsView_Ite mInserting and
EmployeeDetails ObjectDataSourc e_Inserting. The end result is: empty. The
contents of inputParameter are blank. None of the data entered is pass in.
Thus, when my BLL HRPortal.DataAc cess.EmployeeDA L's InsertEmployee
function
receive the InputParameter, aka employee, it fails to add the record.


the EmployeeDetails ObjectDataSourc e_Inserting is your chance to actually
create the parameter, even though the contents of InputParameter are empty.
the problem is that unless you use two-way data-binding, a value from the UI
control will not be passed to the Inserting method. Since in insert case
there is no value you could bind to, the best you could do would be to
create it:
protected void EmployeeDetails ObjectDataSourc e_Inserting( object sender,
ObjectDataSourc eMethodEventArg s e )

{

HREmployee employee = new HREmployee();

...

e.InputParamete rs.Clear();

e.InputParamete rs.Add( "employee", employee );

}

Wiktor Zychla

Jan 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
8705
by: Jim Hammond | last post by:
I am passing the whole object instead or parameters in my select and update methods. I can get the updated object if I set UpdateMethod, let ASP.NET autogenerate an update button, and then press update after making changes, but I don't want that update button. How can I get the updated object when the user presses one of my other action buttons?
3
4072
by: chrisn | last post by:
Hi, (Using ASP.Net 2.0) I have a wizard control inside a detailsview control. When I attempt to call the InsertItem method on the DetailsView I get an error "ObjectDataSource 'ObjectDataSource1' has no values to insert. Check that the 'values' dictionary contains values." I have found I can suppress the error by placing a hidden field inside
0
1874
by: jeffmagill | last post by:
Hi Everybody, I'm really hoping that someone can help me out because I have spent too much time on this project already! Basically, I have a DetailsView that handles all the Edits for a GridView - each row has an edit button and clicking on this should trigger that record to be loaded into the DetailsView for editing. The problem is that the record never gets loaded into the DetailsView. Instead, the DetailsView always and only...
2
14883
by: K B | last post by:
Hi, Is there ANY WAY to hide a row/field in a DetailsView based on meeting a condition at the ItemCreated or ModeChanging event -- or any other way? There appears not to be, but I was hoping for confirmation before totally giving up. Thanks, Kit
7
5425
by: studio60podcast | last post by:
I have a gridview and a details view in a page. The two are hooked up, so that when a row is selected in the GridView, the DetailsView displays the details. But, what I'm trying to accomplish is this: I have two tables - user and item. user table: user_id int user_name varchar(50) item table:
0
1359
by: sansie | last post by:
Hi, I have a page which is basically a details view(in inset mode) inside a datalist. The problem is I want to set the field "invoiceID" (of the detailsview) to an invoiceID coming through the query string of the page. Now, I have sucessfully done this with a detailsview that is not enclosed in a datalist, using the following page load script: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
0
1652
by: =?Utf-8?B?RGVuaXMgU29oZXQ=?= | last post by:
Hi all, I've created a new project to test ObjectDataSource component. I've just added a new objectdatasource, configured it (linked to a table) etc ... It works fine on localhost, i can create, retrieve, update and delete data.
1
4145
by: ledneh | last post by:
I've been working on concurrency checking for an application I'm building, and a minor part of it has me slightly stumped. I've got a DetailsView that populates from an ObjectDataSource, using business objects with optimistic concurrency checking built in in my Save() method (against a timestamp column). This can be proven to work perfectly in the following scenario: - Start app, go to the DetailsView page (defaults to readonly), open a...
5
3466
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration: default.aspx:
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.