I would really appreciate any feedback - thanks in advance.
Webform code:
PrivateSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMyBase.Load
Dim myOrganisationAs CRM.Organisation
Dim strOrganisationIdAsString
strOrganisationId = Request.QueryString("id")
IfNot Page.IsPostBackThen
myOrganisation =New CRM.Organisation
IfNot strOrganisationId =""Then
'read data and push to web form
myOrganisation.GetOrganisastionById(CLng(strOrganisationId))
'organisation_id.Text = CStr(myOrganisation.Id)
title.Text = myOrganisation.Name
OrganisationName.Text = myOrganisation.Name
OrganisationURL.Text = myOrganisation.URL
EndIf
'save in ViewState for postbacks
ViewState("currentOrganisation") = myOrganisation
EndIf
EndSub
ProtectedSub SaveButton_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.Click
Dim myOrganisationAs CRM.Organisation
Dim intResultAsInteger
myOrganisation =CType(ViewState("currentOrganisation"), CRM.Organisation)
myOrganisation.Name = OrganisationName.Text
myOrganisation.URL = OrganisationURL.Text
intResult = myOrganisation.Store()
EndSub
BLL code:
<Serializable()>PublicClass Organisation
Private organisationIdAsLong
Private organisationNameAsString
PublicSub GetOrganisationById(ByVal requestedIdAsLong)
Dim databaseOutputAs DataSet
databaseOutput = CRM.Data.Organisation.GetOrganisationById(requestedId)
organisationId =CLng(databaseOutput.Tables(0).Rows(0)("organisation_id").ToString)
organisationName = databaseOutput.Tables(0).Rows(0)("organisation_name").ToString
EndSub
PublicFunction Save()AsInteger
Return CRM.Data.Organisation.SaveChanges(Me)
EndFunction
End Class
Data Layer Code:
PublicClass DataLayer
PublicClass Organisation
PublicSharedFunction GetOrganisationById(ByVal requestedIdAsLong)As DataSet
Dim params(0)As SqlParameter
params(0) =New SqlParameter("@dotnet.itags.org.organisation_id", requestedId)
Return DataAccessHelper.ExecuteDataSet("select * from organisations where organisation_id=@dotnet.itags.org.organisation_id", params)
EndFunction
PublicSharedFunction Update(ByVal sourceOrganisationAs CRM.Organisation)AsInteger
Dim params(2)As SqlParameter
Dim sqlCodeAsString
sqlCode ="update organisations set organisation_name=@dotnet.itags.org.organisation_name, url = @dotnet.itags.org.url where organisation_id=@dotnet.itags.org.organisation_id"
params(0) =New SqlParameter("@dotnet.itags.org.organisation_id", sourceOrganisation.Id)
params(1) =New SqlParameter("@dotnet.itags.org.organisation_name", sourceOrganisation.Name)
params(2) =New SqlParameter("@dotnet.itags.org.url", sourceOrganisation.Name)
Return DataAccessHelper.ExecuteNonQuery(sqlCode, params)
EndFunction
PublicSharedFunction Insert(ByVal sourceOrganisationAs CRM.Organisation)AsInteger
Dim params(0)As SqlParameter
Dim sqlCodeAsString
sqlCode ="insert into organisations (organisation_name) values (@dotnet.itags.org.organisation_name)"
params(0) =New SqlParameter("@dotnet.itags.org.organisation_name", sourceOrganisation.Name)
Return DataAccessHelper.ExecuteNonQuery(sqlCode, params)
EndFunction
EndClass
EndClass
Without these two methods, it's a little hard to see what's going on.
One other thing to watch is that you haven't got an OnClick= in the .aspx markup as well as the Handles Button1.Click on the VB code. This would result in the the click event handler being called twice.
Dave, thanks for taking the time to have a look at the code. I actually managed to figure out what the problem was lastnight (uk time!).
You must be psychic, it was indeed because I had an onclick attribute on the button, and the same sub is the handler for the button click. Doh!!!
![Embarrassed [:$]](http://pics.10026.com/?src=/emoticons/emotion-10.gif)
Thanks again.
0 comments:
Post a Comment