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.
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]...
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?
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.
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:
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?
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
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?
How to pass a class into another class to a codebehind?
When I debug and check the myCategoryObj in the Default.aspx page, I can see the object is in the debug. What am I doing wrong?
I know I could create the object in the Default.aspx but I should not have to I should be able to call the Business Logic Layer and ask for an object back and then fill the object and pass it back to the Business Logic Layer to be saved (insert or update).
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]...
Would anyone know how to pass a variable to SqlDataAdapter. Here is my code.
TextBox1.Text = 1 Dim textboxval As String textboxval = TextBox1.Text connection.Open()Using connection As New SqlConnection("Data Source=CHRIS-PCSQLEXPRESS;Initial Catalog=TorGHL;Integrated Security=True") Dim dapubcb As New SqlDataAdapter("SELECT [BarName], [MenuSubId], [Address], [PhoneNo], [BarURL], [Email] [BarDescription], [Id], [bg_long], [bg_lat] FROM [BarDetails] WHERE [MenuSubId] = texboxval ", connection)
I have an objectDataSource which uses my stored procedure GetNotifications
And my GridView is bound to that objectDataSource
the only problem is that my stored procedure requires the variable @UserName and then returns the values for that username, but I do not know how to pass the variable to the objectDataSource, does anyone know the code for this?
I can get userName from HttpContext.Current.User.Identity.Name but how do I pass that to the objectDataSource?
i am using,Asp.net(vb),database sql server 2005, i want to use sysdsn DSN for database connection,so please Guide me how do i use DSN using web.config and class(we have sqlhelper type our own DBclass to set connectionstring for whole applicatoin. which get connection string from web.config),
Now,how do i use/set dsn in this type of scenario.
I've changed the definition on one of my tables by removing a field from my data key. However, I still want to pass this field to my stored procedure that inserts fields into this table from another table. The field in question is called ignum. I was using the code
SELECT DISTINCT TblSections.SectionID, TblSections.Description FROM TblSections INNER JOIN UMG.Users ON TblSections.SectionID = UMG.Users.SectionID WHERE (TblSections.Description IS NOT NULL) AND (dbo.Users.LoginName = [@Session(UserName)]) ORDER BY TblSections.Description
I have problem in using Session name in the above BOLD WHERE clause.
This works great for 1 parameter SqlDataSource1.SelectParameters("City").DefaultValue = Me.Page.Title
But I can't figure out how to pass in two parameters in a single statement (See the Select Parameters Below) Two paremeters (City, and Classification) If I set the page title to say "Bismark Charters" Bismark = City & Charters = Classification [Code]... </SelectParameters >
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.
Ive tried a few ways of doing this without success and got together a simplified example so hopefully I can get an answer. When I try to INSERT using a stored procedure InsertTest (normal SQL works OK) I cannot. I need to know how to pass the @Model parameter to the Stored procedure
Have a Stored procedure which can be executed and after entering string for @Model through wizard a new record is created
My asp:SqlDataSource includes InsertCommand="InsertTest" InsertCommandType="StoredProcedure" Also my <InsertParameters includes the asp:Parameter Name="Model" Type="String"/>
My drop down (and I think this is where the problem is ). Record is Inserted after choosing Model and pressing enter
Do I have to set one of the properties in the drop down to tell the Stored procedure the parameter being passed is the parameter Model ??
i have a website with a gridview, i bind the SqlDataSource Control that i use for my Gridview with a StroredProc. but the storedproc has to get a value which is from a textbox so that the gridview can display a record.
I have a form that I need to add a new multiple selection criteria. I added a List Box and I populate it on Load. After user selected his choices I need to pass the values to SQL Select stored procedure. I use C# and SQL. I am not sure how to pass the values and write SQL statment that would select records with the selected values. I also have RAD Teleric list box but again the values need to be passed to sql.