473,724 Members | 2,279 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 2424
>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
8697
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
4071
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
1873
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
14878
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
5423
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
1356
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
1647
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
4142
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
3460
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
8868
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8741
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
9388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9241
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
9160
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,...
0
8062
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4764
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3209
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2149
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.