SQLDataSource - Select Parameter Drawn From A Variable

Mar 4, 2006

I have been using a workaround because i think I don't understand something about sqldatasource select parameters.

I am using control parameters as a workaround for when i want to use a variable at runtime. i assign the value to the control - then use that as my select parameter. is there another way?

here's what i do:

<asp:Literal runat="server" ID="litCurrentYear" Text="" Visible="False"></asp:Literal>

<asp:SqlDataSource runat="server" ID="dsSummaryTable" ConnectionString="***"
SelectCommand="spReportSummary" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter Name="CurrentYear" ControlID="litCurrentYear" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>

On PageLoad I assign litCurrentYear.Text whatever value I want. It works fine. But there must be a more elegant way - I just don't know it yet :)

View 3 Replies


ADVERTISEMENT

SqlDataSource.Update With Session Variable As Input Parameter

May 25, 2007

I'm getting a type mismatch error (currently string, when I think I need Int32 ?) with the code below. I'm having difficultly setting my session variable to type Int32 and having it take up the value of RawCoDeptRowID. When I "Watch" it, it's value remains as "snCoDeptRowID".  Also, not sure if my Update command and it's snCoDeptRowID input parameter is well formed? Any advice would be greatly appreciated. Thank you.
Web Page 1:
Session["snCoDeptRowID"] = Convert.ToInt32 (RawCoDeptRowID);
 
Web Page2:<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
UpdateCommand="UPDATE [CompanyDepartment] SET [User_Name] = @User_Name, [FirstName] = @FirstName, [LastName] = @LastName, [Company_Name] = @Company_Name, [Department_Name] = @Department_Name WHERE [User_ID] = @snCoDeptRowID ">
<updateparameters>
<asp:parameter Name="User_Name" Type="String" />
<asp:parameter Name="FirstName" Type="String" />
<asp:parameter Name="LastName" Type="String" />
<asp:Controlparameter Name="Company_Name" Type="String" ControlID ="ListBox1" PropertyName ="SelectedValue" />
<asp:Controlparameter Name="Department_Name" Type="String" ControlID ="ListBox2" PropertyName ="SelectedValue" />
<asp:QueryStringParameter Name="User_ID" Type="Int32" QueryStringField ="@snCoDeptRowID" DefaultValue ="@snCoDeptRowID" />
</updateparameters>
</asp:SqlDataSource>

View 1 Replies View Related

SqlDataSource + Parameter + SELECT IN

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

SqlDataSource WHERE IN Select Parameter

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

Newbie Help! SqlDataSource + Select Parameter

May 21, 2008

 Why does this not work?        <asp:SqlDataSource ID="employeeSource"            runat="server"            ConnectionString="<%$ ConnectionStrings:mainDB %>"            DataSourceMode="DataReader"            ProviderName="System.Data.SqlClient"            OnSelecting="OnSourceSelecting"            SelectCommand="SELECT * FROM Employees WHERE ID = @employeeID">                        <SelectParameters>                <asp:Parameter Name="@employeeID" Type="Int32" />            </SelectParameters>        </asp:SqlDataSource>In code behind:        protected void OnSourceSelecting(object sender, SqlDataSourceCommandEventArgs args) {            // THIS LINE THROWS EXCEPTION: An SqlParameter with ParameterName '@campaignID' is not contained by this SqlParameterCollection.            args.Command.Parameters["@employeeID"].Value = 3;    // In future, will use dynamic value.        }        If, instead I do this:                    <asp:SqlDataSource ID="employeeSource"            runat="server"            ConnectionString="<%$ ConnectionStrings:mainDB %>"            DataSourceMode="DataReader"            ProviderName="System.Data.SqlClient"            OnSelecting="OnSourceSelecting"            SelectCommand="SELECT * FROM Employees WHERE ID = @employeeID">                        <SelectParameters>                <asp:QueryStringParameter Name="@campaignID" QueryStringField="id" />            </SelectParameters>        </asp:SqlDataSource>(Of course I call page with EmployeePage.aspx?id=123)I get the exception: Must declare the scalar variable "@employeeID".

View 5 Replies View Related

SQLDataSource SELECT Parameter Problem

Mar 13, 2006

I Have a SQLDataSource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"ConnectionString="<%$ ConnectionStrings:SqlServer %>"ProviderName="<%$ ConnectionStrings:SqlServer.ProviderName %>"SelectCommandType="StoredProcedure"SelectCommand="pe_getAppraisals" ConflictDetection="CompareAllValues"><SelectParameters><asp:ControlParameter ControlID="ddlPType" PropertyName="Value" Direction="Input" Name="PType" ConvertEmptyStringToNull="true" /><asp:ControlParameter ControlID="ddlClient" PropertyName="Value" Direction="Input" Name="Client" ConvertEmptyStringToNull="true" /><asp:Parameter Direction="Input" Name="PageSize" DefaultValue="20" Type="Int32" /></SelectParameters></asp:SqlDataSource>
When I load the page no results are returned. The only way I get results is to select an item from both drop down lists... My stored procedure works if I pass NULL or '' (an empty string) for PType and.or Client. Any Ideas on how to fix this or work around it? Is there any way for me to see what is being passed to the database for these values before I select an item from the dropdown lists?
Thank YouJason

View 3 Replies View Related

SQLDataSource Provide Select Parameter Value Programmatically

Sep 9, 2007

Hey All for some reason I can not get this right and/or find what I am looking for.
I have an SQLDataSource with a PartID set as the filtered value in the Datasource Query.
I am trying to use code beside to set the value and I am failing...lol...
Here is my attempt at it,
SqlDataSource1.SelectParameters("PartID") = txtPartID.Text
Any help would be great!

View 2 Replies View Related

Variable In Select Parameter

Mar 7, 2008

Hi,
I am trying to get the login name of a user, trim off some characters, which works fine, convert this to a string variable, which works fine and then use this variable in an sql select parameter.
I've tried countless things and am not sure why my variable @NewString is not working in the Select command. If I add a default value I know is present, it works, but it can't seem to pick up the variable value of NewString. It prints out as expected in the response.write statement, but I really need it to connect to the corresponding value in the database.
Any ideas are greatly appreciated-code below.
Thanks,
Liz
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<SCRIPT LANGUAGE="vb" runat="server">
Public Function LoggedOnUser() As StringReturn (Request.ServerVariables("LOGON_USER"))
End Function
</SCRIPT>
<%Dim MyString As String = LoggedOnUser()
Dim MyChar As Char() = {"O"c, "N"c, "E"c, ""c}Dim NewString As String = MyString.TrimStart(MyChar)Response.Write("Hello ")
Response.Write(NewString)
%>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pboConnectionString %>"
SelectCommand="SELECT [LastName], [FirstName], [logon] FROM [Phonebook] WHERE ([logon] = @NewString)">
<SelectParameters>
<asp:Parameter DefaultValue="" Name="NewString" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="logon" HeaderText="logon" SortExpression="logon" />
</Columns></asp:GridView>
</asp:Content>

View 2 Replies View Related

SQL Server 2012 :: Create Variable In Select Query And Use It In Where Clause To Pass The Parameter

Sep 9, 2014

I am writing a stored procedure and have a query where I create a variable from other table

Declare @Sem varchar (12) Null
@Decision varchar(1) Null
Select emplid,name, Semester
Decision1=(select * from tbldecision where reader=1)
Decision2=(select * from tbldecision where reader=2)
Where Semester=@Sem
And Decision1=@Decision

But I am getting error for Decision1 , Decision2. How can I do that.

View 6 Replies View Related

SELECT A Single Row With One SqlDataSource, Then INSERT One Of The Fields Into Another SqlDataSource

Jul 23, 2007

What is the C# code I use to do this?
I'm guessing it should be fairly simple, as there is only one row selected. I just need to pull out a specific field from that row and then insert that value into a different SqlDataSource.

View 7 Replies View Related

Tasks In The Designer Not Being Drawn Correctly

Aug 14, 2007

I've got a really irritating problem where the designer is not redrawing the design time window properly. For tasks in my package I can only see the names and the arrows indicating flow control, but not the boxes around each task and the icons. This happens in both Control Flow and Data Flow tabs. As a workaround I have to click on each task, which then renders it properly.

My version of the designer is:

Microsoft SQL Server Integration Services Designer
Version 9.00.3042.00

Microsoft Visual Studio 2005
Version 8.0.50727.42 (RTM.050727-4200)
Microsoft .NET Framework
Version 2.0.50727

View 5 Replies View Related

What Is The Best Parameter To Use For A Sqldatasource When The Parameter Is The Sqlmembership Username?

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

Getting Variable Value Out Of A SqlDataSource In Asp 2.0

Apr 30, 2006

How can i get a variable value out my SqlDataSource.  Step by step this is what i am trying to do.

I have a SqlDataSouce
it has a @Genera variable in it.
i would like to store this variable in a different variable named GeneraType.
 
I am new to asp and have tried a number of thing but with no success. I can figure out the code
 
This is what i have for code:
 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            DeleteCommand="DELETE FROM [SongsCW] WHERE [songID] = @songID" InsertCommand="INSERT INTO [SongsCW] ([uNameID], [createdatetime], [Genera], [sName], [sAlisName], [notes], [userName], [ANA]) VALUES (@uNameID, @createdatetime, @Genera, @sName, @sAlisName, @notes, @userName, @ANA)"
            SelectCommand="SELECT * FROM [SongsCW]" UpdateCommand="UPDATE [SongsCW] SET [uNameID] = @uNameID, [createdatetime] = @createdatetime, [Genera] = @Genera, [sName] = @sName, [sAlisName] = @sAlisName, [notes] = @notes, [userName] = @userName, [ANA] = @ANA WHERE [songID] = @songID" OnSelected="SqlDataSource1_Selected">
            <DeleteParameters>
                <asp:Parameter Name="songID" Type="Int32" />
 
 
code behind lag C#
 
 
 
protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        string GeneraType;
       
    }
 
 
Thanks in advance for any help!

View 3 Replies View Related

Using SQLDataSource To Populate Variable BoundField

Nov 19, 2007

I am using a SqlDataSource in my form page to query the DB and populate a GridView. If for example the value of Cell (3) is "1" I want to display the values of two other fields, Cells (6) & (7) in two ASP BoundFields 4 and 5. 
Then, When Cell(3) = "2"  I want to compare two Cells (8) & (9) procede as above, placing those values in ASP BoundFields 4 and 5.
Ive tried using the code below to do the comparisons of all the fields that I am using and then not displaying them with "Visible=False" as I dont want all the fields to be visible... But this method has become quite cumbersome to manage.
Is there a better way to do this??
Thanks!
 
 Protected Sub TestStatus_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then                        If e.Row.Cells(3).Text = 1 Then
                e.Row.Cells(4).Text = "<font color=Green><b>" & e.Row.Cells(6).Text & "</b></font>"                e.Row.Cells(5).Text = "<font color=Red><b>" & e.Row.Cells(7).Text & "</b></font>"
                e.Row.Cells(6).Visible = False                e.Row.Cells(7).Visible = False                e.Row.Cells(8).Visible = False                e.Row.Cells(9).Visible = False
            End If
            If e.Row.Cells(3).Text = 2 Then
                e.Row.Cells(4).Text = "<font color=Orange><b>" & e.Row.Cells(8).Text & "</b></font>"                e.Row.Cells(5).Text = "<font color=Blue><b>" & e.Row.Cells(9).Text & "</b></font>"
                e.Row.Cells(6).Visible = False                e.Row.Cells(7).Visible = False                e.Row.Cells(8).Visible = False                e.Row.Cells(9).Visible = False
            End If        End If    End Sub

View 1 Replies View Related

Populating An SqlDataSource Using A Session Variable

May 29, 2008

I'm having a real problem populating my SqlDataSource and was wondering if anyone could help.  I'm sure it's something simple
First off, I created a session variable on a previous page like so Dim NewSubscribeID As Integer = Convert.ToInt32(retSubcribeID.Value)
Session("SubcribeID") = NewSubscribeID
I now want to use this session variable on another page to populate a SqlDataSource like so <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionXX %>" SelectCommand="spXX" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="SubscribeID" SessionField="SubscribeID" Type="Int32" DefaultValue="0" />
</SelectParameters>
</asp:SqlDataSource>
Here is the problem... Only the default value gets used.
I've tried putting the session variable into a label to test that it does actually exist lblTest.Text = Session("SubcribeID")

 and it does...What am I doing wrong?

View 2 Replies View Related

SqlDataSource Parameter

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

Using LIKE And A Parameter In SqlDataSource

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

Need To Set &<asp:Parameter&> On SqlDataSource

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

Add Parameter To SqlDataSource

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

Passing '% Variable %' To SqlDataSource Through E.Command.Parameters

Feb 23, 2008

 Hello all,I'm writing a site with one page that uses the session variable (User ID) to pick one user ID out of a comma separated list in the field Faculty. The default parameterized query designed in the SqlDataSource wizard only returns lines that contain an exact match:SELECT * FROM tStudents WHERE ([faculty] = @faculty) The query: SELECT * FROM tStudents WHERE ([faculty] LIKE '%userID%') works as I need when I hard code the query with a specific user ID into the SqlDataSource in the aspx page.  It will not work if I leave the @faculty parameter in it:SELECT * FROM tStudents WHERE ([faculty] LIKE '%@faculty%') e.Command.Parameters works to replace the @Faculty with a user ID, but again, adding the single quote and percentage sign either causes errors or returns no results.  I've tried several variations of:         string strEraiderID = "'%" + Session["eRaiderID"].ToString() + "%'";        e.Command.Parameters["@faculty"].Value = strEraiderID;no results are returned, not even the lines returned with the default select query.How do generate the equivalent of SELECT * FROM tStudents WHERE ([faculty] LIKE '%userID%') into the SqlDataSource? Thanks much! 

View 3 Replies View Related

SqlDataSource: Getting Parameter Value From ViewState

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

Using XML As An Update Parameter In A SqlDataSource?

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

Pass A Parameter To A SqlDataSource

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

SqlDataSource Parameter Direction

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

Need Help With SQLDataSource Update Parameter

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

Parameter Name Questions In SqlDataSource????

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

How To Make New Parameter In Sqldatasource?

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

SQLDataSource Expects Parameter

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

SqlDataSource And Parameter Binding

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

Read Single Piece Of Data From SqlDataSource To A Variable?

Jan 17, 2006

First I want to say thanks to the folks how have helped me over the past week or two.
I'm missing a crucial piece of insight. How do I read a single piece of data from a SqlDataSource which only hold one row of data into a declared variable?
string zUserName = SqlDataSource.(get the value in the row that is labeled UserName)
It really doesn't matter to me whether it is an SqlDataSource or some other data container that hold the data I've selected. My goal is to be able to read some data from some predefined datasource into a declared variable.
If I am approaching this problem in the wrong way any advice or article links you could give me would be grealy appreciate.
Thanks, Bill

View 1 Replies View Related

SqlDataSource Query Parameter Problem

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

SqlDataSource Parameter Binding (Updating)

Oct 6, 2006

Hello, I just started working with ASP.NET.I'm trying to use the CheckBoxList Control.  As I understand it, you can bind a SqlDataSource to this control and it loads the list for you.  However tp precheck the items, you have to do this manually.  This part works fine.  Next part was to save whatever the user checks.  I wrote stored Procedure and now just trying to pass 1 parameter to the stored procedure using a second SqlDataSource.  I get the error: "A severe error occurred on the current command.  The results, if any, should be discarded."Here is the second datasource I am using to try and save the data:<asp:SqlDataSource ID="sds_PersonRole" runat="server" ConnectionString="<%$ ConnectionStrings:Development %>"SelectCommand="usp_selectPersonRole"SelectCommandType="StoredProcedure"UpdateCommand="usp_updatePersonRole"UpdateCommandType="StoredProcedure"><SelectParameters>    <asp:ControlParameter ControlID="gv_Person" Name="PERSON_ID" PropertyName="SelectedValue" Type="Int32" /></SelectParameters><UpdateParameters>    <asp:Parameter Name="strXML" Size="8000" Type="String" />    <asp:Parameter Direction="InputOutput" Name="err_msg" Type="String" Size="150" DefaultValue="0" /></UpdateParameters></asp:SqlDataSource>I have a code behind file with the following modules:  (btnEditPerson is clicked to start the process.  the sds_PersonDetails is updated via form contolls and works fine.)  Error occurs on the bolded line (Stored procedure is just accepting the string and saving to a field.  It works fine, I tested it.  Its just erroring out before  it runs the stored procedure. Protected Sub btnEditPerson_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEditPerson.Click    sds_PersonDetails.Update()    gv_Person.DataBind()    sds_PersonRole.Update()End Sub     Protected Sub sds_PersonRole_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles sds_PersonRole.Updating        Dim command As Data.Common.DbCommand        command = e.Command        'un-check all checkboxlist items (count - 1 to account for starting at 0)        Dim listCount As Integer = cbl_Role.Items.Count() - 1        Dim strXML As String        strXML = "<personRole>"        For x As Integer = 0 To listCount            If cbl_Role.Items(x).Selected() = False Then                strXML = strXML & "<person id='" & gv_Person.SelectedValue & "' />"                strXML = strXML & "<role id='" & cbl_Role.Items(x).Value & "' />"            End If        Next        strXML = strXML & "</personRole>"        command.Parameters("@strXML").Value = strXML        lbl_ErrMsg.Text = command.Parameters("@err_msg").Value.ToString()    End Sub

View 1 Replies View Related

SqlDataSource Using A Type Parameter Of Table

Oct 8, 2006

I am not sure (and I've been known to overlook things) if it is possible to use a Table parameter type as parameter to a stored procedure?  Is it possible? I would prefer not to create a SQL batch statement calling an stored proc w/ one parameter over and over. Instead i'd rather just create the stored proc to take a table parameter and pass the table into the stored proc.  I know I could use a CSV string of IDs instead of a table...  or I could create a big SQL batch and use that.  But I'd rather not. Could anyone provide some guidance? Thanks!Joe

View 2 Replies View Related







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