DataSource Controls :: Include Method In ADO.NET?
Mar 10, 2010difference between these two codes would be?
[Code]....
difference between these two codes would be?
[Code]....
I have an ObjectDataSource that I want to perform updates using a business entity i.e. Type="Object"). Since the values for the entity are within a user control, I have stored a reference to the control in Session and in the updating event, set the new instance to the value of the entity from the user contol property (which also pulls values from the form viaother properties of the control):
Protected Sub MasterDataSource_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles MasterDataSource.Updating
Dim entity As New Login()
Dim accountControl As AccountInfo = TryCast(Session("AccountCtrl"), AccountInfo)
entity = accountControl.Entity
e.InputParameters.Add("entity", entity)
End Sub
And here's the markup for the datasource:
<asp:ObjectDataSource ID="MasterDataSource" runat="server" EnableCaching="true" CacheDuration="10"
SelectMethod="SelectAll" UpdateMethod="Update" TypeName="Data.DAL.LoginDAL">
</asp:ObjectDataSource>
My question is, how can I get the update method to pass this entity to the update method in my BLL class? It seems the Update method requires an ID or reference to the original object to use in determining whether any changes have taken place, but I don't really want to do this. In other words, I just want to use the Update event on my ObjectDataSource to pass my entity to the method ("Update") I set as a property and then let this business method handle the update of the data. Shown below, is the BLL update method I want to call:
Public Overloads Function Update(ByVal entity As Login)
If entity Is Nothing Then
Throw New ArgumentNullException("entity")
End If
MyBase.Update("UpdateLogin", entity.Username, entity.Password, entity.FirstName, entity.LastName, entity.Role, entity.Region, _
entity.Email, entity.Title, entity.TierID, entity.Street, entity.City, entity.State, entity.Zip, entity.Mobile, entity.Phone, entity.Fax)
End Function
When I try to call this as it stands now, I get an error: ObjectDataSource 'MasterDataSource' could not find a non-generic method 'Update' that has parameters: ID, entity. Previously, I'd set up a long list of parameters of basic data types (string, int, boolean), but this is rather cumbersome and I was hoping to use an entity for this (FYI, I also got the same type of error when I tried this approach, but with the ID as the
last parameter in the list). Perhaps what I'm doing here is atypical to how the ODS is normally used?? Has anyone done something like this successfully?
I have a formview with an entityDataSource. I need to include columns from related fields. I have seen many demos, with AdventureWorksDB, that imply that you can do this by using INCLUDE in the entitydatasource declaration. I have tried made many attempts and it just does not seem to work as demonstrated. I have attached the errors below and the EDS. I have also attached a JPEG of the model I am working in. Three errors demonstrating 3 different attempts to include a related table:
DataBinding: 'TmModel.tbICObjectBase' does not contain a property with the name 'Group'
the code declaration for error 1:
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Group") %>' />
DataBinding: 'TmModel.tbICObjectBase' does not contain a property with the name 'tbICTagBase'.
the code declaration for error 2:
<asp:Label ID="Label1" runat="server" Text='<%# Bind("tbICTagBase.Group") %>' />
DataBinding: 'System.Data.Objects.DataClasses.EntityCollection`1[[TmModel.tbICTagBase, TmModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' does not contain a property with the name 'Group'.
the code declaration for error 3:
<asp:Label ID="tbICTagBasesLabel" runat="server" Text='<%# Bind("tbICTagBases.Group") %>' />
EntityDataSource
<asp:EntityDataSource ID="entDSObjectBase" runat="server" AutoGenerateWhereClause="True"
ConnectionString="name=IntouchDBContainer" Include="tbICTagBases"
DefaultContainerName="IntouchDBContainer" EnableFlattening="False"
EntitySetName="tbICObjectBases" EnableDelete="True" EnableInsert="True"
EnableUpdate="True" EntityTypeFilter="tbICObjectBase">
<WhereParameters>
<asp:SessionParameter SessionField="Tag" Name="RecID" Type="Int64" />
</WhereParameters>
</asp:EntityDataSource>
You can see the model at [URL] Or [URL]
I have an application that I am developing using ASP.Net with visual basic code. I have a table called "Customers" that contains 3 fields. The name of each field is "Name", "LocationA", and "LocationB". I want to code a select query that list two columns. The first column should contain the field "Name". I want the second column to contain the value in the field "LocationB" if "LocationB" is not null, else I want the second column to contain the value in the field "LocationA".
View 4 RepliesIm building on a transaction website that gives the user a few choices for them to choose when they want to view their transactions history
They can choose:
1.Current Month
2. Last 1 month and current month
3. Last 2 month and current month
4. Select date range
How do I include this variable in the stored procedure?
I have 5 linkbuttons act as navigation menus on the top of each .aspx page. I wrote code to control when and which linkbutton should be enabled. I am going to create a header.ascx page with these 5 linkbuttons and use <%=Response.Write("header.ascx")%> code to include the .ascx file in the .aspx page. But I got a problem with the code behind, the current .aspx page does not recongnize the linkbutton objects because they are in another file. How do I declare these 5 linkbuttons in the application?
View 13 RepliesI created a simple search form which populates a gridview from sql server. I use 'contains' on a varchar(max) field which has a full text index. I find if I do a search for "Mexico Argentina", I get multiple results, which is good.One thing my sql server stored procedure is doing is inserting the word 'AND' between words. I do this because I want all words to be found. So if the user inputs "Mexico Argentina", I am converting that to "Mexico AND Argentina"But if I have even one 'noise word' in the search string, I get no results at all. For instance, there might be a sentence in my database table saying "I prefer Mexico to Argentina" but if I put that sentence in, I get no results at all. The database is seeing my converted string:I AND prefer AND Mexico AND to AND ArgentinaAnd finds nothing.I also have another form, which does a more advanced search that allows 'exact phrase'. If the user chooses 'exact phrase', then I don't insert AND anywhere. Instead, I surround his phrase with 4 apostrophes - 2 before the phrase, and 2 after.So now the database sees:' ' I prefer Mexico to Argentina ' ' (I've put a space between apostrophes here to make it clearer to view.Now I not only get no results, I get an error message.
View 1 Repliesi have two sqldatasource controls. one i use to display data in textbox's ,filter'd by a select parameter in page behind code. Once checked, i want to copy this data to the other datasource ,by selecting checkbox.Then display this data in detailsview control.
At present the two datasource controls declared , render data to the page simultaneously during pageload. I want to first check data in textbox's from first source, before second datasource is rendered to screen. note, both are filtered by a page variable. i wish to leave the textbox datasource control in situ, as other controls and code depend on it.The other detailsview datasource is my problem?
I have a Public Sub listed in a class file that I am using to store Select, Update,etc...methods for an Object Datasource. When I attempt to configure the datasource, the Class appears as a business object, but the sub within the class is not available for method selection. (It does not appear in drop down list in wizard.)
The sub exists, so where is a good place for me to start looking for a fix? I have part of the class file listed below:
[Code]....
My Business Logic Layer has AddItem method that add's to Items table in db along with an entry in Balance table.AddItem method uses two TableAdapters Items & Balance. Both these have corresponding Business Objects as Item and Balance.
Here is the AddItem method :
[Code]....
ASPX Page with DetailsView & ObjectDataSource
[Code]....
Now executing this page generates error as
ObjectDataSource 'ObjectDataSource2' could not find a non-generic method 'AddItem' that has parameters: _item, _balance, ItemName, GroupId, CategoryId, AuId, Rate, TotalStrScale, OffsStrScale, OffsAE [code]...
to call some piece of c# code via a trigger in sql, and if it is what's the easiest method to go about doing it.
View 3 RepliesI have one main doubt for long perioad, If we access the DB using SqlDataSource and ObjectDataSource, Can i know which is the fastest accessing the DB.
View 5 RepliesI right click on a TableAdapter, select Add Query, select using QueryBuilder, then select a field to filter upon, and add Filter as =@BookStem. Automatically the QueryBuilder adds the WHERE clause to my new query:HERE (BookStem = '@BookStem')When I press OK, I get "BookStem in expression is not part of the query". And filtering doesn't work.
View 1 RepliesI'm having a question about an update method using SQL To Entities. I'm sending an object to the class and i'm updating him sucefully, but i need to specify each property of object instead of update in once. For example
[Code]....
In this case, i'm updating name, age and country sucefully but i want to use instead of update each property one-by-one, something like this:
[Code]....
So, the C = New should fill the C with all New values on properties, but this isn't work. To update an object, i've to update each property individual or can i update all in one like C = New?
i am having a datatable with 10 rows.
Out of this 10 rows 3 Rows have their RowState as Added, 2 rows as Modified, and 4 as Deleted.
Now i want to use Datadapter's InsertCommand, UpdateCommand and DeleteCommand
Is it possible to update datatable's changes to Database with Single DataAdpater.Update(DataTable) Call.
Means i will call DataAdapter.Update(DataTable) method only once and with this all new added rows should be inserted in database, modified rows should be updated and deleted rows should be deleted from Database.
i have this class
class MyDal
{
IList<MyData> GetAll(string orderBy, , int count, int firstIndex, out int totalRowCount);
}
i'm using an objectdatasource with MyDal to bind values to a gridview.
i want know if there's a way to configure the objectdatasource to use the parameter totalRowCount without calling the SelectCountMethod.
Should I just write to file before a stored procedure is executed or should I log the stored procedure into a table? If the latter one is recommended, how should I go about doing that?
View 4 RepliesI've an ObjectDataSource & its datasource from typed dataset which is bind to 3 textboxes.
One of that textbox text concatenate with other two textboxes values.
Some thing like this,
textbox1.text=textbox2.text & textbox3.text
How can I customize my insert query for this?
I could not see the insert query in my objectdatasource.
Here is the "Update" method which is not updating.
It works if I remove "@original_UnitPrice" and "@original_OnHand" parameters from the "WHERE" clause.
[Code]....
How and where can I get the returnvalue from my "DeleteGuestById" method to show the right error message to my user?
I have this:
Protected Sub gvGuestlist_OnRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvGuestlist.RowCommand
If e.CommandName = "DeleteGuest" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim data As DataKey = gvGuestlist.DataKeys(index)
Dim GuestId As Integer = data.Values("id")
odsGuestlist.DeleteParameters.Clear()
odsGuestlist.DeleteParameters.Add("id", GuestId)
odsGuestlist.Delete()
End If
End Sub
In my BLL:
<System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, False)> Public Function DeleteGuestById(ByVal ID As Integer) As Integer
Dim returnval As Integer
GuestlistAdapter.DeleteGuestById(ID, returnval)
Return returnval
End Function
I think I have to be in the ObjectDatasources' "OnDeleted" method but I have no what code to place there.
I have a dataset where I would like to upper all string fileds and when done check each field for a value. The other way i thought to do it is to do an upper of each string when I do the conditional check. I would like to know what is quicker upper of the values in the dataset or upper in the conditional statement? Knowing the dataset will contain a max of 10.000 rows and there are multiple conditional statements in the complete process.
View 4 RepliesHDSK_AUTO HDSK_ID HDSK_CASEDESC
1 TC1 pc spoil
2 TC2 problem
Action table:
ACT_AUTO ACT_HDSK_ID ACT_DATE ACT_TIMEIN
ACT_TIMEOUT ACT_ACTIONS ACT_STATUS
[code]...
How do I go about doing this in SQL? I need to return 3 columns: ID, the stuff combined into a single field, and the latest status of each ID. (by latest I mean the most recent entered record's ACT_STATUS. this could be based on the ACT_AUTO I think, which is the auto-increment number)
I've got the following scenario:
one object datasource configured with a storedprocedure that has PROCEDURE [dbo].[GetContractsPaged] ( @startRowIndex int, @maximumRows int )
but later I realized that I needed an extraparameter so first I tried to add an extra parameter as a filter like:
<asp:ObjectDataSource ID="odsContrato" runat="server" DeleteMethod="Delete" InsertMethod="Insert" SelectMethod="GetContractsPaged" EnablePaging="True" TypeName="Facturacion.DAL.ContratoDataLayer" UpdateMethod="Update" SelectCountMethod="TotalNumberOfContratos"
FilterExpression="emprnume ='{0}'">
<FilterParameters>
<asp:SessionParameter Name="emprnume" SessionField="emprnume" Type="String" />
</FilterParameters>
Which worked fine but with one problem... apparently selectcount method is ignoring filter parameter and is returning the full set of data. Surfing the net I found that select parameters when used are also taken by seleccount method... the problem is that when I used:
<SelectParameters>
<asp:SessionParameter
Name="emprnume"
SessionField="emprnume"
Type="String"
/>
</SelectParameters>
Inmediately, I received the error : ObjectDataSource 'odsContrato' could not find a non-generic method 'GetContractsPaged' that has parameters: emprnume, maximumRows, startRowIndex.
So I decided to modify my stored procedure to receive an additional parameter and modify my class to reflect the change but when trying to use it I kept on receiving the same error I showed above in bold.
I have an SQLSiteMapProvider that needs a unique URL and have not got the smarts to work out how to get the provider to do the work so for now I thought I would just add the data to the DB then edit the URL with the ID. I can't do this on the first insert as I do not know the ID as it is an auto generated Primary Key
I tried to us the PostBackURL to go to a 2nd Page that got the New ID and added it to the end of the already known URL "Page.aspx?ID=" but apparently you can't do that as I found out (This would have been a masive hack to the problem I know but it would have got around it issue of for now)
this is how I guessed it would work
Insert Data with URL "Page.aspx?ID=" and more data.... Then Get New ID and update URL to have the ID on the end ie: Page.aspx?ID=99
i need to find, string or boolean from database..
that is, i have a table i need to check that is string or boolean? to assigne other vairable?
using some extensions methods?