DataSource Controls :: Passing Object To ObjectDataSource.SelectParameters Collection

Mar 30, 2010

I'm trying to use an ObjectDataSource's SelectMethod() to retrieve a result set from a sql server database to populate a data table with various stored procs that have any given number of parameters. My approach is to pass an object which contains the stored proc name and information about its parameters into the SelectMethod(). My issue is that I don't know how to actually set the default value. Here is the code I have so far:

ObjectDataSource1.DataObjectTypeName = "WebApplication1.Children";
ObjectDataSource1.TypeName = "WebApplication1.Children";
ObjectDataSource1.SelectMethod = "Select";

Parameter odsParameter = new Parameter() { Name = "storedProc", Type = TypeCode.Object };

// How do you set the default value to reference an object?

ObjectDataSource1.SelectParameters.Add(odsParameter);

namespace WebApplication1
{
public class Children
{
public DataTable Select(object storedProc)
{
// do stuff here and get db values.
}
}
}

The default value of a Parameter object is a string type. Does anyone know how to set the default value with an object or how I can pass an object into the SelectMethod?

View 2 Replies


Similar Messages:

DataSource Controls :: Passing Parameters To ObjectDataSource

Aug 9, 2010

I followd Brian Orrell LINQ tutorial for paging/sorting and created a gridview bound to an ObjectDataSource through a method call which gets data from adatabase. My form includes two buttons with a textbox next to each one of them. I need to be able to populatte th egridview depending on the button that was pressed, I cannot figure out how signal my method which button was pressed.
[Code]....
[URL]

View 1 Replies

MVC :: Passing Json Collection Object From View To Action

Nov 1, 2010

I am trying to send json data from view to controller action. But the issue is the data is not populating in the action parameter List<Score>.

View Model:
public class Score
{
public int QuestionId { get; set; }
public int PrevAnswerId { get; set; }
public int CurrAnswerId { get; set; }
public string CurrAnswerName { get; set; }
}

Json Data look like:
[
{QuestionId:1, PrevAnswerId:3, CurrAnswerId:3, CurrAnswerName:'Known to Broker'},
{QuestionId:2, PrevAnswerId:7, CurrAnswerId:7, CurrAnswerName:'Completed'},
{QuestionId:3, PrevAnswerId:10, CurrAnswerId:10, CurrAnswerName:'Report'}
]

On window load, I will construct the Json object using "eval()" function and do some operation in the data before its save. On Save Click, I will call the action through the ajax call.

$.ajax({
url: url,
type: "GET",
dataType: 'json',
data: {score: ScoreJson},
contentType: "application/json; charset=utf-8",
success: function () {
alert("succes");
},
error: function () {
alert("error...");
} });

Action:
public ActionResult SaveScore(List<Score> score)
{
// do something...
}

But here score comming as collection of 3 elements with zero(for interger property)/null(for string property) values. When I checked in the request I found the data in "parama" property like.

"Score%5b0%5d%5bQuestionId%5d=1 &Score%5b0%5d%5bPrevAnswerId%5d=3 &Score%5b0%5d%5bCurrAnswerId%5d=3 &Score%5b0%5d%5bCurrAnswerName%5d=Known+to+broker&
Score%5b1%5d%5bQuestionId%5d=2 &Score%5b1%5d%5bPrevAnswerId%5d=7 &Score%5b1%5d%5bCurrAnswerId%5d=7 &Score%5b1%5d%5bCurrAnswerName%5d=Completed&
Score%5b2%5d%5bQuestionId%5d=3 &Score%5b2%5d%5bPrevAnswerId%5d=10 &Score%5b2%5d%5bCurrAnswerId%5d=10 &Score%5b2%5d%5bCurrAnswerName%5d=Travelers+Report&".

But I am not sure why it is not getting populated in the score list. One full day I spent for this issue but till now I didnt find the solution for this issue.

View 4 Replies

Web Service - Passing A Base Object With List / Collection?

Apr 9, 2010

We need to create a simple web service in ASP.NET that can be called from PHP or other languages. This in turn will be used to update records in a database for an item submission.

The core part is fairly simple, we have a base set of fields for the object - first name, last name, birth date, city, etc. In addition however we need to accept a list of items associated with that object that can range from 0-n.

Jan 1 2009, ABC
May 1 2010, 123
Jun 30 2010, XXXXX

What would be the best way to structure this so it can be easily passed to the ASP.NET web service and processed as a single call for the entire object? Would passing the list of items as a single delimted string be a wise approach? Ex: Jan 1 2009, ABC|May 1 2010, 123|Jun 30 2010, XXXXX

View 1 Replies

DataSource Controls :: Pass Object As SessionParameter In ObjectDataSource?

Dec 28, 2010

Is it possible to pass a domain object as session parameter in an ObjectDataSource. I'm doing this:

<asp:ObjectDataSource ID="ParticipantsDataSource" runat="server" OnInit="SqlDataSource_Load"
SelectMethod="LoadParticipants" TypeName="SB.Web.units.Players">
<SelectParameters>
<asp:SessionParameter Name="user" SessionField="User" Type="SB.BusinessLogic.DomainEntity.User" />
</SelectParameters>
</asp:ObjectDataSource>

But I get the error message that I can't create an object of the type System.TypeCode from the string containing SB.BusinessLogic.DomainEntity.User for the property Type.

View 1 Replies

DataSource Controls :: Objectdatasource Return Inserted Object Like LinqDatasource Do?

Mar 5, 2010

I would like the ObjectDatasource insert and update data methods to return the inserted or updated object like LinqDataSource do.

View 2 Replies

DataSource Controls :: How To Pass An Object To The Selectmethod Of The Objectdatasource Control

Mar 31, 2011

how to pass an object to the selectmethod of the objectdatasource control?

View 2 Replies

DataSource Controls :: Make ObjectDataSource Typename Of A Singleton Business Object?

Mar 14, 2010

How do I make ObjectDataSource work with singleton Business object? My singleton business object is defined in Global:

[Code]....

I get an error:The type specified in the TypeName property of ObjectDataSource 'objThreads' could not be found.

View 2 Replies

DataSource Controls :: Pass Selectparameters To A DAL Class?

Mar 16, 2011

I have a webform whose ObjectDataSource reads an xml file to populate a GridView in the .aspx page. I have to hard code the file path in the .cs file defining the ObjectDataSource classes. I want to be able to use a portion of the query string to indicate which file to select, but, normal methods, like Server.MapPath and Http.Request.Current don't work in the class page. how I can pass values from the SelectParameters configured in the ObjectDataSource down to the ObjectDataSource method? Here is my Class code:

[Code]....

The filePath variable is what I want to be able to alter based on my query string.

View 1 Replies

DataSource Controls :: SelectParameterS Multiple Parameters?

Oct 4, 2010

I want to pass to a DataSource(SQL, Linq) more than one SelectParameter or what ever will do the work.I have many ArtistIds i want to pass to my source, so that it will display only those entries with my Parameters.My Problem is, that i dont know in which Format i can pass more than one Parameter, till now i used QueryStrings but that only works for one Parameter, no? I have a DataTable filled with all my IDs and im system-caching it to pass it from a Search-Site to a Detail-Site, maybe theres a better way?

This is my Source:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MvcMusicStoreConnectionString %>"
SelectCommand="SELECT Album.Title, Album.Price, Album.AlbumArtUrl, Artist.Name, Genre.Name AS Expr1 FROM Album INNER JOIN Artist ON [code]...

View 1 Replies

DataSource Controls :: Access SelectParameters In Code?

Jan 10, 2011

I am building up asp:ControlParameters in my SqlDataSource at design time that all have ControlIDs based on textboxes and radiobuttons in my form, and those seem to work OK. Now, I want to build my SQL select query up in the PageLoad event and I can't seem to get the values of these SelectParameters. If at design time I create a ControlParameter like:

[Code]....

...why is it giving me an error saying "ERROR: Microsoft SQL Server: Must declare the variable '@cp_employee_last_name'"? That SQL Where clause should just be whatever the user typed into tbEmployeeLastName.Text, right?

View 1 Replies

DataSource Controls :: Assigning Values To SelectParameters In Code?

May 6, 2010

I want to define SelectParameters for my SqlDataSource in markup and then assign values in code, but when I use the syntax:

[Code]....

It works the first time, but won't let me re-add the parameters on subsequent postbacks.

I can't use ControlParameters in this case because the values in the controls are loaded from xml files and some minor parsing needs to be done to the values before they're passed to the database.

View 2 Replies

Forms Data Controls :: DetailsView Delete Method Passing Null Values To Objectdatasource Underlying Object Delete Method

Apr 12, 2010

I am using VS 2008 SP1. My also have included CSS Friendly adapter [URL] in my project ( I mentioned this because my GridView Empty data template is not showing when using GridView's CCS Friendly adapter). I have a GridView and a DetailsView. When a record in GridView is selected its details information is shown in the Details View. Type of Data source I am using is ObjectDataSource. My Insert and Update methods works perfectly. It is only the Delete method that is passing null values to the underlying object delete method. My source codes for both the UI, BLL, DAL is shown below

[Code]....

My Business Object code is below :

[Code]....

My Data Access Layer Code is:

[Code]....

View 2 Replies

Web Forms :: Passing Text Box Value From Aspx.cs Page To SelectParameters In Page

Sep 5, 2010

I would like to take a value from a text box and pass it as a search parameter to my database. I get the value from my code behind page as follows: protected void btn_click(Object sender, ImageClickEventArgs e)

View 2 Replies

Forms Data Controls :: Passing Null Values To ObjectDataSource

Jan 4, 2011

This is an ASP.NET 3.5 web app written in C# using VS2008 and connecting to an MS SQL backend. It is using ad hoc queries in a strongly typed dataset to pull from the database. This query (shortened for clarity) is designed to allow optional input of parameters (a requirement) or pull all records if no parameters are input. It works normally in SQL Server Management Studio with the addition of Declare and Set statements and it works normally in the TableAdapter's Query Builder:

[Code]....

The markup contains this ObjectDataSource, which is tied to the TableAdapter with the above query:

[Code]....

The problem I'm having is in passing null values to the ODS to feed to the query. Tying the ODS parameters directly to the dropdownlists and textboxes didn't work. Got an error message that there was a mismatched data type. Tried several combinations of code to feed the right values to the ODS parameters but couldn't find one that worked. Is the problem in the query or am I setting up the code-behind wrong? Here's the code:

[Code]....

View 9 Replies

SQL Server :: How To Query Return All Data In Array Object / Collection Object

Sep 14, 2010

how to query return all data in Array Object ,Hash Table ,And DataTable dataRow

View 4 Replies

Forms Data Controls :: Reference To An Object's Collection?

Jan 31, 2011

I have a custom object and a generic collection of this object.When databinding, how can you get a reference to the object's collection similar to how DataRow.Table works? I understand I may need to write code to handle this but I'm not sure where to start.I considered adding a property to my custom object class to store the collection in, but would this generate too much overhead setting this for every object in the collection?

View 3 Replies

How To Get The Inserted Id Or Object After An Insert With The FormView/ObjectDataSource Controls

Feb 22, 2010

I have a series of classes that loosely fit the following pattern:

public class CustomerInfo {
public int Id {get; set;}
public string Name {get; set;}
public class CustomerTable {
public bool Insert(CustomerInfo info) { /*...*/ }
[code]...

View 1 Replies

Forms Data Controls :: ObjectDataSource For GridView Is Not Creating Original_{0} And New Values Object?

Mar 9, 2010

I am trying to update record in gridview using ObjectDataSource (with conflict detection)The following is the ObjectDataSource

[Code]....

Update Method is as follows

[Code]....

In ObjectDataSourceProducts_Updating(..) event , I am checking objects which are being sent to UpdateProduct(..) method. I found that both the objects " original_ProductDB and productDB " have the same the values. When I click "Update" in GridView after entering new value, ObjectDataSource is not picking new value

[Code]....

GridView is as follows.

[Code]....

ProductBO is as follows

[Code]....

View 3 Replies

MVC :: Passing A Collection Of Objects To The View?

Apr 16, 2010

I'm trying to pass a list of items from a LINQ query to a View, but I'm having trouble figuring out how to resolve a type issue. Here's the error:

The model item passed into the dictionary is of type 'System.Data.Linq.DataQuery`1[Project.Models.Diagnostic]' but this dictionary requires a model item of type 'Project.Models.Diagnostic'.

The issue seems to originate with this code from my Controller:

[Code]....

I tried changing the IQueryable<Diagnostic> to var and got the same error. Also played around with something like:

[Code]....

But then VS2008 says that diagnostics could never be null, and that's may not the best (or even valid) way to do it.

View 1 Replies

DataSource Controls :: ObjectDatasource And Class As Datasource

Jun 24, 2010

I am really having a hard time trying to write something from scratch I created a 'Person' Class.Public Class Person

Private _FirstName As String = ""
Private _LastName As String = ""
Private _Age As Integer = 0
Public Sub New(ByVal FirstName As String, ByVal LastName As String, ByVal Age As Integer)
FirstName = FirstName
_LastName = LastName
_Age = Age
[code]...

View 1 Replies

Forms Data Controls :: Use (create And Bind A Object Collection) A Repeater Control Complete Through Codebehind?

Mar 14, 2010

i am developing a sharepoint webpart. In this webpart i need to use a repeater control. The problem is, i can only use codebehind for creating and using the control. So i have some questions:

1. After creating the repeater control in codebehind, how to create some templates (itemtemplate, footertemplate, etc.) and use it?

2. How to bind a object collection to a repeater control?

View 2 Replies

Forms Data Controls :: Sort Functionality Not Working When Binding The Grid To A Collection Type Object?

Apr 1, 2011

My Grid is bound to a collection type datasource. When I try to sort the Columns in the Grid I get Javascript error saying sorting event not implemented. Why is the default inbuilt sort functionality not working which worked fine when I directly used a sqlDataSource using smart tag. Do I have to write some code to achieve sorting ?

View 1 Replies

Web Forms :: Passing Collection To User Control

Apr 28, 2010

I'm dynamically loading a user control from a for loop against a objects collection, eg.

[code]....

I want to pass the following collection into the user control: oPerson.Address[i].listHistory (listHistory is a List of objects which I want to manipulate inside the usercontrol)

How can I pass this into the usercontrol so i can do this

View 10 Replies

Asp - ObjectDataSource UpdateMethod Passing Updated Values

Mar 24, 2010

I've got a gridview connected to an objectdatasource which is bound to some custom objects in my code (code is below). The problem I'm having is that the value passed into my update method is the old value, not the new value. Thoughts?

Imports System.Configuration
Imports System.Web.Configuration
Imports System.Security.Cryptography
Imports System.Collections.Generic

Partial Public Class ManageUsersControl
Inherits System.Web.UI.UserControl
Dim auth As AuthenticationSection
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Users.DataBind()
End Sub
End Class

Public Class Users
Private sName As String
Private sPassword As String
Public Sub New()
End Sub
Public Sub New(ByVal nm As String, ByVal pass As String)
Name = nm
Password = pass
End Sub
Public Property Name() As String
Get
Return sName
End Get
Set(ByVal value As String)
sName = value
End Set
End Property
Public Property Password() As String
Get
Return sPassword
End Get
Set(ByVal value As String)
sPassword = value
End Set
End Property
End Class

Public Class UserData
Dim auth As AuthenticationSection
Shared userTable As List(Of Users)
Public Sub New()
auth = CType(WebConfigurationManager.GetSection("system.web/authentication"), AuthenticationSection)
End Sub
Public Function CreateData() As List(Of Users)
Dim dt As New List(Of Users)
For Each user As FormsAuthenticationUser In auth.Forms.Credentials.Users
dt.Add(New Users(user.Name, user.Password))
Next
userTable = dt
Return userTable
End Function
Public Function SelectMethod() As List(Of Users)
If userTable Is Nothing Then
Return CreateData()
Else
Return userTable
End If
End Function
Public Function UpdateMethod(ByVal userInfo As Users) As Integer
Dim user As FormsAuthenticationUser = auth.Forms.Credentials.Users(userInfo.Name)
Dim pass As String
Dim sha As New SHA1CryptoServiceProvider()
Dim enc As New System.Text.ASCIIEncoding()
pass = enc.GetString(sha.ComputeHash(enc.GetBytes(userInfo.Password)))
userTable.Add(New Users(userInfo.Name, pass))
user.Password = pass
Return 1
End Function
End Class

and the markup:

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ManageUsers.ascx.vb" Inherits="mystuff.ManageUsersControl" %>
<asp:GridView ID="Users" runat="server" AutoGenerateColumns="False"
AutoGenerateEditButton="True" AutoGenerateDeleteButton="True"
DataSourceID="UsersData">
<Columns>
<asp:BoundField DataField="Name" HeaderText="User Name" />
<asp:TemplateField HeaderText="Password" >
<InsertItemTemplate>
<asp:TextBox runat="server" ID="InsertPassword" Text='<%# Bind("Password") %>' />
</InsertItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="EditPassword" Text='<%# Bind("Password") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server">*****</asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="UsersData"
DataObjectTypeName="mystuff.Users"
UpdateMethod="UpdateMethod"
SelectMethod="SelectMethod"
TypeName="mystuff.UserData"
runat="server"
OldValuesParameterFormatString="original_{0}"></asp:ObjectDataSource>

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved