Using A Custom Object As Sqldatasource Parameter
Dec 29, 2007
hi i want to select data based on a user id, which is stored in a custom object-> sessionhandler.user.id
how can i put that in the select parameter?
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:RentTodaySQL %>" DeleteCommand="DELETE FROM [Rentals] WHERE [RentalID] = @original_RentalID"
InsertCommand="INSERT INTO [Rentals] ([Headline], [Description], [MoveInSpecial], [MonthlyCost], [Deposit], [AvailableDate], [FeaturedListing], [UserID], [Address], [Address2], [City], [State], [Zip], [LeaseTermID], [LeaseDetails], [Section8], [Section8Details], [PetsAllowed], [PetsDetails], [PetDeposit], [ApplicationFee], [ApplicationDetails], [SmokingAllowed], [RentalCategoryID], [Bedrooms], [Bathrooms], [SqFootage], [LotSize], [YearBuilt], [DefaultImageID]) VALUES (@Headline, @Description, @MoveInSpecial, @MonthlyCost, @Deposit, @AvailableDate, @FeaturedListing, @UserID, @Address, @Address2, @City, @State, @Zip, @LeaseTermID, @LeaseDetails, @Section8, @Section8Details, @PetsAllowed, @PetsDetails, @PetDeposit, @ApplicationFee, @ApplicationDetails, @SmokingAllowed, @RentalCategoryID, @Bedrooms, @Bathrooms, @SqFootage, @LotSize, @YearBuilt, @DefaultImageID)"
OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Rentals] WHERE ([UserID] = @UserID)"
UpdateCommand="UPDATE [Rentals] SET [Headline] = @Headline, [Description] = @Description, [MoveInSpecial] = @MoveInSpecial, [MonthlyCost] = @MonthlyCost, [Deposit] = @Deposit, [AvailableDate] = @AvailableDate, [FeaturedListing] = @FeaturedListing, [UserID] = @UserID, [Address] = @Address, [Address2] = @Address2, [City] = @City, [State] = @State, [Zip] = @Zip, [LeaseTermID] = @LeaseTermID, [LeaseDetails] = @LeaseDetails, [Section8] = @Section8, [Section8Details] = @Section8Details, [PetsAllowed] = @PetsAllowed, [PetsDetails] = @PetsDetails, [PetDeposit] = @PetDeposit, [ApplicationFee] = @ApplicationFee, [ApplicationDetails] = @ApplicationDetails, [SmokingAllowed] = @SmokingAllowed, [RentalCategoryID] = @RentalCategoryID, [Bedrooms] = @Bedrooms, [Bathrooms] = @Bathrooms, [SqFootage] = @SqFootage, [LotSize] = @LotSize, [YearBuilt] = @YearBuilt, [DefaultImageID] = @DefaultImageID WHERE [RentalID] = @original_RentalID">
<SelectParameters>
<asp:Parameter DefaultValue="<%= SessionHandler.User.ID %>" Name="UserID" Type="Int32" />
</SelectParameters>
View 1 Replies
ADVERTISEMENT
Feb 22, 2007
Hi,
I am trying to get the selected options from a listbox and either pass a SqlDataSource object the array or loop through it and pass each element of the array. I then need to modify the returned databtable to graphing function, but first drop the last column. I was wondering if anyone can help me with the following:
1. Pass an array into SqlDataSource Select OR 2. Pass a single argument into the Select statement and populate a datatable without it writing over the current row each time it iterates through the foreach statement. I am looking for the dataview to append to dt each time it loops. Is there a property for dataview that behaves like the "ClearBeforeFill" for table adapters?3. Update a parameter programmatically
Below code works, but I think it can be more efficient. Any suggestions would be greatly appreciated.
Thanks in advance!!
DataTable dt = new DataTable(); DataTable dt2 = new DataTable(); DataView dv = new DataView();
foreach(ListItem liOptions in ListBox1.Items) { if(liOptions.Selected) { SqlDataSource1.SelectParameters.Add("Parameter1", liOptions); dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty); dt2 = dv.Table; dt.Merge(dt2); dt2.Dispose(); SqlDataSource1.SelectParameters.Clear(); } }
if (dt.Rows.Count > 0) { Graph(dt); //Pass original datatable (dt) to Graph(); dt.Columns.RemoveAt(2); //Reformat datatable (dt) and remove last column before binding to Gridview1
GridView1.DataSource = dt; GridView1.DataBind(); } else {
errorMessage.Text = "No data was returned!"; }
View 3 Replies
View Related
Apr 2, 2007
I wrote a C# class that has a couple of methods that can be called to grab data out of a flat file and import it to a DB. This class was written for a web applicaiton originally. (class has many complex business rules in it)
Now I would like to use this same class in a SSIS package.
Is it possible in a script task to create a new object with my class and use it's methods?
In the end all I want SSIS to do is create my object, call a method in that object and be done.
If I was doing this in DTS, I would have to create an .Net EXE that used my class but I'm hoping to avoid that in SSIS.
Frenchy
View 19 Replies
View Related
May 29, 2008
If a page contains a SQLDataSource object with a connection string that works on other pages, can that datasource be used in the codebehind to create a DataReader thereby avoiding the need to DIM and create a new connection string? My code fails but I can't figure out what to try next. Thanks.
Dim queryString As String = "SELECT * FROM users "
Using SqlDataSource1
Dim command As New Data.SqlClient.SqlCommand(queryString)
Dim oReader As Data.SqlClient.SqlDataReader = command.ExecuteReader()
' Call Read before accessing data.
While oReader.Read()
Console.WriteLine(String.Format("{0}, {1}", oReader(0), oReader(1)))
End While
' Call Close when done reading.
oReader.Close()
End Using
View 9 Replies
View Related
Mar 15, 2008
I know i can accomplish this by setting a session variable on page load on the server side (Session["UserName"]= User.Identity.Name) and then use a session parameter, but I was wondering how to do it without using session variables, i was hoping the following code would work, but it doesn't. Thanks for any ideas.
" Name="UserName" Type="String" />
View 3 Replies
View Related
Jan 23, 2006
Can we create custom object wide roles? In the same manner that db_datareader in effect grants SELECT on all tables, can we create roles that affect all objects without having to explicitly grant the permission on every object?
View 1 Replies
View Related
Apr 7, 2007
Hello, thanks for reading my post!
Ok, so I connected to my database. I can insert data and all that good stuff, but when it comes time to make the login page for a project I am working on, sadly I cant figure out how to read data from my datasource object O_O.
So I have an SqlDataSource object, its bound to my sql database ( successfully ), I can even set it to return the results I want, my question though is how do I access the results it returns so I can compair it with code?
Hope I'm making sense! Any help is *greatly* appreciated!
Thanks!,
-Bob
View 2 Replies
View Related
Nov 8, 2007
.. the Membership ProviderUserKey value as the parameter of a stored procedure ?It seems obvious to me that you would want to do this, but I can only see that it allows you to pass Profile parameters.
View 2 Replies
View Related
Dec 6, 2005
Hi,Using VB.net I have created a custom object (hope my terminology is correct here), it’s just a class that defines a few string, integer, and hash table variables. After creating an instance of this class and populating it with data I need to be able to store this instance of my object in a sql server data base table. How do I do this? I saw an article that used the image data type to achieve this (code was in java unfortunately) is this the correct approach. Could you please give me some code examples
Thanks
View 1 Replies
View Related
Sep 13, 2006
I am trying to set the value of a SqlDataSource parameter named "InvestmentGroup" with the following code:ProjectData.SelectParameters["InvestmentGroup"] = Request.QueryString[0];ProjectData.DataBind();When I try this, I get an error saying that the right side is a string and the left side is not....but I cannot find a property of the SelectParameters["InvestmentGroup"] object like Value or something that would allow me to set the value of the parameter with a string. Please help!
View 4 Replies
View Related
Oct 27, 2006
Background - I have a page that uses a numeric value stored in a Session object variable as the parameter for three different SQLDataSource objects, which provide data to two asp:Repeaters and an asp:DataList. Also, in the Page_Load, I use this value to to seed a stored procedure and an SQLDataReader to populate several unbound Labels. This works fine. In addition, I have a collection of 6 TextBoxes, an unbound Listbox, and two Buttons to allow the user to do searching and selection of potential matches. This basically identifies a new numeric value that I store in the Session variable and PostBack the page (via one of the buttons). This also works fine.Problem - I have been tasked with taking a different page and adding six textboxes to collect the search values, but to post over to this page, populate the existing search-oriented TextBoxes, adn programmatically triggering the search. Furthermore, I have to detect the number of matching records and, if only 1, have the Repeaters and DataList display the results based on the newly selected record's key numeric value, as well as populating the unbound Labels. I have managed to get all of this accomplished except for programmatically triggering the Repeaters and DataList "refresh". These controls only populate as expected if a button is clicked a subsequent time, which makes sense, since that would trigger a PostBack and the Page_Load uses the new saved numeric key value from the Session.My history in app development is largely from Windows Forms development (VB6), this is my second foray into Web Form dev with ASP.NET 2.0. I am willing to acceptthat what I am trying to do does not fit into the ASP environment, but I have to think that this is something that has been done before, and (hopefully) there is a way to do what I need. Any ideas, oh great and wise Forum readers? *smile*
View 3 Replies
View Related
Mar 6, 2007
I am updating data with sqlDatasource but it is inserting NULL, tell what I am missing <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1"
DefaultMode="Insert" Width="100%">
<InsertItemTemplate>
<table width="100%">
<tr>
<td style="width: 100px">
Name</td>
<td style="width: 100px">
<asp:TextBox ID="txtCategory" runat="server" Text='<%# Eval("CategoryName") %>'></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
Parent</td>
<td style="width: 100px">
<asp:DropDownList ID="ddlParent" runat="server" DataSourceID="SqlDataSource1" DataTextField="CategoryName" DataValueField="CategoryID" Width="100%">
</asp:DropDownList></td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
<asp:Button ID="btnAdd" runat="server" Text="Add" CommandName="Insert"/></td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CommerceTemplate %>"
SelectCommand="SELECT [CategoryID], [CategoryName], [CategoryMID] FROM [CMRC_Categories]"
DeleteCommand="DELETE FROM [CMRC_Categories] WHERE [CategoryID] = @CategoryID"
InsertCommand="INSERT INTO [CMRC_Categories] ([CategoryName], [CategoryMID]) VALUES (@CategoryName, @CategoryMID)"
UpdateCommand="UPDATE [CMRC_Categories] SET [CategoryName] = @CategoryName, [CategoryMID] = @CategoryMID WHERE [CategoryID] = @CategoryID">
<DeleteParameters>
<asp:Parameter Name="CategoryID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="CategoryName" Type="String" />
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="CategoryMID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:FormParameter Name="CategoryName" Type="String" FormField="txtCategory" />
<asp:FormParameter Name="CategoryMID" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource> Please suggest cheers
View 4 Replies
View Related
May 21, 2007
I'm an "old" programmer but new to ASP.NET.
I want to get a value from the SQL Dataset.
What I would normally do in other environments is iterate through the dataset to get the value I would be intrested in, but I can't figure out how to do this without using a visual data display object like a Grid view.
Typically I want to get a value from the database that I then after manipulating it, like multply by 5, use to format something on the page.
thanks in advance,
Thommie
View 3 Replies
View Related
May 8, 2008
PLEASE PLEASE PLEASE......
I did not get a single response for the last 6 hours... And during this time I was searching and trying to understand the problem but I am really stuck. If this is the wrong forum to ask this question, please redirect me. Really begging for replies...[:'(]
If I use the custom SQL statements in SqlDataSource, the application runs fine within the development environment (VS2005) but errors out if I publish the web site and access outside of the environment. In order to find-out the problem, I made the following test:
I created a select statement in one SqlDataSource to fill-in a GridView. I used the exact same statement to create a stored procedure and used that SP in second SqlDataSource and I fill a second GridView. When I debug or run the application, both grids are filled OK and everything works fine. However, when I publish the web site and try to do same only the stored procedure works fine and when I try to fill the grid using the built-in SQL, the page gives error. The error mesage is as follows when I use the address 'localhost':
Server Error in '/' Application.
The SELECT permission was denied on the object 'Contacts', database 'Homer', schema 'dbo'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: The SELECT permission was denied on the object 'Contacts', database 'Homer', schema 'dbo'.Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[SqlException (0x80131904): The SELECT permission was denied on the object 'Contacts', database 'Homer', schema 'dbo'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +859322.......da da da .......
If I access the page using the IP address the message chages to below but it is not the issue, I just give it if it helps to find the problem:
Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
My SqlDataSource s are like this: <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HomerConnectionString %>"
SelectCommand="TestRemoteAccess" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="Param1" PropertyName="Text" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:HomerConnectionString %>"
SelectCommand="SELECT FirstName, LastName, Business FROM Contacts WHERE (ContactID = @Param1)">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox2" Name="Param1" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
Environment: SQL Server 2005, VS2005, Vista
View 1 Replies
View Related
Dec 1, 2006
I have a SqlDataSource that has a parameter that I am trying
to set.
The item is stored in a session field called “GameObject�
Game Object is a simple class that has a several variables.
I am trying to access the .name data member of the class.
<asp:SessionParameter Name="GameCode" SessionField="((GamingSystem)Session[‘GameObject’]).Name" />
This does not work. Is there a way to declarative bind to
the item that I am for.
View 3 Replies
View Related
Oct 3, 2006
I'm using a GAC-installed assembly as part of a Reporting Services
(2005) report. The code does not need any permissions beyond execution.
All it does it take today's date and calculate last week's start and
end date. It's all just datetime manipulations. All methods are static.
In
the VS2005 report designer, I can do everything fine. The code runs as
expected and defaults the parameters to the right date.
When I
upload the rdl to the Report Server, I get the message "Error during
processing of €˜Start€™ report parameter.
(rsReportParameterProcessingError) ". If I override the "Start"
parameter, it doesn't give me that error anymore. Start should be the
Sunday of the previous week.
I have deployed the signed assembly to the GAC on the report server as well as the bin folder for reporting services. Because it doesn't need anything beyond execution, I shouldn't have to modify any config files, right? I have already restarted IIS & the Reporting Services service.
What am I missing?
View 10 Replies
View Related
Jan 22, 2008
This is probably a simple question, but I have a form with two content windows. In content1 using an sqldatsource1 I select a single record and display it using a FormView.
What I need to do is using one field from sqldatsource1 ("CategoryName", which is not displayed in formview1), in content window 2; I need to display all records with the same CategoryName.
So the simple English version is:
Using CategoryName from SqlDataSource1 (in content window 1), select all records in SqlDatasource2 where CategoryName is = CategoryName (in content window 2).
I am using vb code behind.
Thanks
View 1 Replies
View Related
Mar 2, 2008
I have a SqlDataSource, a GridView and a TextBox (whose ID is searchTB) on my page. I can use the SqlDataSource like this:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=TORNADO;Initial Catalog=AdventureWorks;Integrated Security=True"
ProviderName="System.Data.SqlClient"
SelectCommand="select * from production.product where name = @nameparam">
<SelectParameters>
<asp:ControlParameter ControlID="searchTB" Name="nameparam"
PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
However, I want the search to be made using the LIKE operator, ie, select * from production.product where name LIKE %THE_TEXT_FROM_TEXTBOX%.
How can I do this? Thanks
View 5 Replies
View Related
Mar 31, 2008
Hi there,
I'm still new, so please be patient with me...
I am using C# ASP.NET 2.0. I have a web page that uses a Calendar control to display links for events from my database. The links use the __doPostBack to pass the EventID back to the same page. I was getting the EventID as a string okay and then passing it into a TextBox control. I then had an SqlDataSource control that set to display the Event in a DetailsView. The SqlDataSource uses a control to get the EventID - I used the TextBox control. It is all working fine, but...
What I want to do is instead of using a TextBox control - pass the string in to a public property in the class in my code-behind. I want to use an <asp:Parameter> on my SqlDataSource control to set the control to get the EventID from my public property. How do I do this?
Thanks in advance.
View 3 Replies
View Related
Jun 3, 2008
I have a gridview which is displaying a bunch of data. However, I'd only like to display data based on the query string. Here's my code: <asp:GridView ID="gv" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CssClass="GridControl" DataKeyNames="ID">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" Visible="false" SortExpression="ID" />
<asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="Details.aspx?id={0}" Text="Details" />
<asp:BoundField DataField="Name" HeaderText="Attendee" SortExpression="Name" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:conn %>" SelectCommand="sprocCUSTOM_GetDetail" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>and my stored procedure: SELECT ID, Name, Email FROM Events WHERE (ID = @eventID) So as you can see, I need to get the value from the query string to add to my stored procedure. I know this can be done in the code-behind, but isn't there a way to add <SelectParameter> to the SqlDataSource? I just can't get the query string in there.
View 12 Replies
View Related
Jun 6, 2007
Hello,
Is it possible to add a multivalued parameter to a report from C#? I already have a C# .dll which I reference in the report. If so, could someone give some hints on how to do it?
As I searched the net for an answer to this, I came across ReportExecutionService. It looks like it's what I want, but I cant find the dll to reference in order to used this class. Does anyone know?
If it is not possible to do this from C#, then can someone please give an example on how to do it from Custom Code?
Thanks
/Peter
View 1 Replies
View Related
Aug 25, 2006
Hello all, This may be a simple question, but it is causing me some grief at the moment.I put a SqlDataSource control on my form, and pointed it to the stored procedures I had written to insert/update/delete rows in my database.The DataSource control notices that I am using parameters in my queries, and asks me to select where the parameters will be assigned from (Control, Form, Session, etc.)I am keeping the primary key value (in this case an ID number for a real estate listing) persisted in ViewState.Is there any way to access ViewState from the SqlDataSource control, or do I need to find another way to do this? Thanks,Adam
View 1 Replies
View Related
Nov 6, 2006
One of the requirements of the UpdateParameters for a GridView I'm building is that the fields that are being edited via EditItemTemplates are passed back to the UpdateParameter as XML. How would I go about combining the fields from the GridView/EditItems into an XML string that I can set as an asp:Parameter?
Thanks.
View 1 Replies
View Related
Feb 28, 2007
I'm trying to pass my SqlDataSource a parameter that is defined in the code-behind file for the same page. I've tried the method below but it does not work. Is there a better way?SubmitForm.ascx page: <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ connection string...... %>" SelectCommand="sp_CourseMaterialShipment_GetCourses" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:Parameter DefaultValue="<% ProgramID %>" Name="programID" Type="Int32" /> </SelectParameters></asp:SqlDataSource> SubmitForm.ascx.vb page:Private ProgramID as string = "25"Public ReadOnly Property ProgramID() As String Get Return _ProgramID End GetEnd Property ThanksJason
View 2 Replies
View Related
May 4, 2007
Hi,
In the SqlDataSource control if I go to the SelectQuery property and I set one parameter with the “direction� property to “Output� the result doesn’t display in the control, why?
Points:
The procedure witch is in the selectquery property the parameter in it is set to output two.
View 3 Replies
View Related
Jun 14, 2007
I need to know how to setup the ControlParameter for a template control in my Gridview? I have a datepicker in my template and I need to know how to refer to it in the ControlParameter of the SQLDataSource control.
<UpdateParameters>
<asp:ControlParameter Name="dp_start" ControlID="bdpPlanStart" PropertyName="SelectedValue" Type="Datetime" /> Here is the template:<asp:TemplateField HeaderText="Start" SortExpression="dp_start">
<ItemTemplate>
<%#DataBinder.Eval(Container, "DataItem.dp_start", "{0:d}")%>
</ItemTemplate>
<EditItemTemplate>
<BDP:BasicDatePicker id="bdpPlanStart" SelectedValue='<%# DataBinder.Eval(Container.DataItem,"dp_start") %>' runat="server" DateFormat="d">
</BDP:BasicDatePicker>
</EditItemTemplate>
</asp:TemplateField>
View 1 Replies
View Related
Jul 2, 2007
I have a table with with some column name includes a space. for example [Product ID] [Product Name] Instead of Product_ID, Product_Name. when I try to create a gridview and enable delete, insert. It just won't work.
I've been trying for several hours without success. When I click on delete. the page postback without any error, but the record doesn't get deleted or updated.
<asp:SqlDataSource id="sourceProducts" runat="server" SelectCommand="SELECT [Product ID], [Product Name] FROM Products" ConnectionString="<%$ ConnectionStrings:mydb %>"DeleteCommand="Delete from Products where [Product ID]=@ProductIDUpdateCommand="UPDATE Products SET [Product Name]=@ProductName WHERE [Product ID]=@ProductID" > <UpdateParameters> <asp:Parameter Name="ProductName" /> <asp:Parameter Name="ProductID" /> </UpdateParameters> <DeleteParameters> <asp:Parameter Name="ProductID" Type="Int32"/> </DeleteParameters></asp:SqlDataSource><asp:GridView ID="GridView2" runat="server" DataSourceID="sourceProducts" AutoGenerateColumns="False" DataKeyNames="Product ID" > <Columns> <asp:BoundField DataField="Product ID" HeaderText="ID" ReadOnly="True" /> <asp:BoundField DataField="Product Name" HeaderText="Product Name"/> <asp:CommandField ShowEditButton="True" ShowDeleteButton="True"></asp:GridView>
Another testing I did was to use another table with no space in the Column name, Product_ID, Product_Name. and I can't name my parameter as PID, PNAME. I have to name it as @Product_ID, @Product_Name in order for Delete, update to work. My understanding is if I declare the parameter explicitly(<asp:Parameter Name="PID" />, I can use any name I want. Did I must missed something?
I'm new to ASP.NET, could someone help me?
Thanks.
View 5 Replies
View Related
Jul 20, 2007
I'm sure that is really simple, but how do I pass a parameter with multiple value to a SQLdatasource?
ex: SELECT field1 from tblTableA where idTableA IN ( @Param1)
Let's say I want to pass 1,2,3,4 as Param1 (SELECT field1 from tblTableA where idTableA IN ( 1,2,3,4))
How I am supposed tu use the .SelectParameters.Add() to pass a list of integers instead of a single value??
Thanks in advance.
View 2 Replies
View Related
Dec 5, 2007
Is it possible to use a WHERE-IN statement with a SqlDataSource control. For instance:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT [Id], [Name], [Phone] FROM [Table1] WHERE ([Id] IN @Id)">
<SelectParameters>
<asp:Parameter DefaultValue="( 1, 3, 5, 7, 11 )" Name="Id" Type="Int32" />
</SelectParameters></asp:SqlDataSource>
I'm hoping the gridview would then display a table with rows for records 1,3,5,7,11. Thanks for any help...
View 2 Replies
View Related
Jan 31, 2008
Hi there,I'm new to db stuffs and I'm using sqldatasource to pull my data from the server. Here's the codes.<asp:SqlDataSource ID="testSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:p01impConnectionString %>" SelectCommand="SELECT [a], [b], [c], [d], [e] FROM [MYDB] WHERE (([a] = @a) AND ([b= @b))" CancelSelectOnNullParameter="False"> <SelectParameters> <asp:ControlParameter ControlID="TextBox1" Name="a" PropertyName="Text" Type="String" /> <asp:ControlParameter ControlID="TextBox2" Name="b" PropertyName="Text" Type="String" /> </SelectParameters></asp:SqlDataSource> notice that I haven't used [c], [d], [e] and I want to declare a parameter, something like: Total = c + (d*e)can anyone show me the syntax to do this UNDER sqldatasource? I then will have to put that Total in a gridview (i can solve this part)Thanks
View 1 Replies
View Related
Dec 14, 2005
Problem: The system throws the following error"Procedure or Function 'sp_TestRequestFormMaster_StatusChange' expects parameter '@Status', which was not supplied."I'm using VS 2005 Final.Recreate the problem:I've created a simple stored procedure with two parameters on SQL 2005 on Win 2003 Server. @ID INT, & @Stutus INTOn a SQLDataSource Control for the Delete query, using the build button to open the Command and Parameter Editor, I click the Refresh Paramater.I set ID Parameter Source: Control, ControlID: GridView1I set Status Parameter Source: None, DefaultValue: 1001.Partial Source View:
<DeleteParameters><asp:ControlParameter ControlID="GridView1" Name="ID" propertyName="SelectedValue" Type="Int32" DefaultValue="" /> <asp:Parameter DefaultValue="1001" Name="Status" Type="Int32" /><asp:Parameter DefaultValue="" Direction="ReturnValue" Name="RETURN_VALUE" Type="Int32" /></DeleteParameters>I run the code, click the delete in the GridView and the error appears. How can I pass a status value without relating it to a source.
View 1 Replies
View Related
Jan 10, 2006
Hi, I am using a SQL DataSource with a few parameters. I need to specify the value of the parameters at run time but I need a custom way to do it as the value needs to be calculated not come from Cookie, Control, Form, Profile, QueryString or Session. Is there a way to bind your own value to these parameters. For instance if I had a variable how would I bind that to the parameter?
At the moment i am doing the following which works but I dont think it is the correct way
dsMyDataSource.SelectParameters["MyParameter"].DefaultValue = MyCalculatedValue;
In previous projects i have added a value to the Session and then bound the parameter value to the session but that doesnt seem like a good solution either.
Thanks for any help you can give.
Martin
View 9 Replies
View Related
Aug 8, 2006
Hi, I have a little problem with a SqlDataSource.
A table in my database has an ID collumn, which is an integer auto-increment. The datasource has a SelectQuery with an [ID] parameter, which it retrieves from the querystring.
I want the DataSource to return all rows when no querystring parameter is passed, and when an ID is given via the querystring, a 'WHERE' clause in the SelectQuery would return only certain records.
However, suppose I have the following query:
SELECT * FROM SomeTable WHERE ([ID] = @ID)
When I bind @ID to the QueryString with '*' as DefaultValue, it throws an exception saying it can't convert '*' to a smallint, which makes sense.
I haven't got a clue how to solve this, except for using different DataSources based on the presence of the querystring parameter.
Any idea's?
View 7 Replies
View Related