.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to view the Query with parameters

Posted By:      Posted Date: October 01, 2010    Points: 0   Category :ASP.Net

I run queries in my stored procedure and pass values to it as a perameter e.g.

SELECT p.Profile_Id

FROM   Profile p
WHERE  (p_Gender = p.gender_id)

now is there a way that i can get the actual query executed with paramaters value like this:-

SELECT p.Profile_Id

FROM   Profile p
WHERE  ('M' = p.gender_id)

View Complete Post

More Related Resource Links

How to Encrypt Query String Parameters in ASP.NET

Encrypt Query String Parameters in ASP.NET.u can send secure data one page another page u can also use query string to encrypt

view state vs request parameters


If  the view state is the data entered into the form fields then they are supposed to be available in the request parameters or request body. Then why would we need view state for?


SqlDataSource and Parameters query


Hi everyone,

I'm on the edge wondering is it possible ? I have got 2 questions. Please help me out.

1. I have a GridView on my page and it uses sqldatasource with parameterized query. What I want to do is, on page load (where nothing has been selected so no parameter supplied), I want it to query everything (something like SELECT * FROM [this_table]) but since my SelectCommand is something like

SELECT * FROM [this_table] WHERE [this_column] = @someParameters AND [that_column] = @someParameters.

Can I play around with default value to achieve something like that but how ? Now, when the page loads, it doesn't show anything (No Gridview).

2. On my page, I made something like (username, gender, address, and more) and one single search button. That means, no single control enable auto postback. What I am trying to accomplish is building dynamic query

(if username specifed -> SELECT * FROM [this_table] WHERE [username] LIKE @username).

If both username and gender are specified (SELECT * FROM [this_table] WHERE [username] LIKE @username AND [gender] = @gender) and you know the rest. How can I do this using GridView and SqlDataSource ? To my knowledge, I can only specify one SELECT statement in a sqldatasource.  I am stucked and desparately looking for help. Thanks all.

How to pass page column value to data view parameters

Hi All, I have a page library with custom column, lets call it "FormCourseId". On that page I have data view which retrieves data from custom list filtered by page column "FormCourseId". In parameter wizard creates the following tag <ParameterBinding Name="ListCourseId" Location="Form(FormCourseId)" DefaultValue=""/> Then I try to use that parameter in XSLT of data view as a filter creteria.  <xsl:param name="CourseId"></xsl:param> It does not work for me. If I change data view parameter source from Form to Query String and pass parameter as url one it works fine. What is wrong with page column parameter binding? May be if FormCourseId column is not presented in form layout as a field(I do not need to show that field in user form of the page) it could not be treated as form parameter?

Why do we need Common view fields in content query web part?

I am a bit confused on the purpose of "CommonViewFields" in CQWP. Almost all the write-ups on the web says that if we need a custom column to be available in the web part's XSL, we need to export the webpart file, add the columns to "CommonViewFields", import the web part to the site. However I noticed that, when I create a custom style template in my "ItemStyle.xsl" and simply add a line like <xsl:value-of select="@MyCustomColmn"/>, then "MyCustomColumn" appears automatically under "Fields to display" in the tool pane as a text box prompt, when I edit the web part and select my style template. I can then simply fill-in my column display name under "MyCustomColumn" and the web part works perfectly fine. (There is NO NEED to export the web part, edit the ".webpart" file and add "commonviewfields" etc..etc..etc) If this works, then what is the real need for "commonviewfields" ? Can someone shed light on this? I am totally confused.. (SharePoint 2010)          

how to create a Tree View using passing one sql query

(1)  SELECT a.HD, a.HEAD, a.SH, a.SUBHEAD, a.TRK, a.TRACK, a.TGT, a.TARGET, a.PDC, a.DT_RELEASE, a.STATUS, a.CO  FROM V_HIERARCHY1 a(2) and Data isHR    HR    Rec    Records    Leave    Leave Records    HRL.0001    Policy and Process for leave record.    27.06.2010    30.06.2010    WIP    EdlinkHR    HR    Rec    Records    Leave    Leave Records    HRL.0002    Quarterly Review    01.07.2010    04.07.2010    Planned    EdlinkHR    HR    DB    Database    SAL    Salary    DDS.0001    Calculation of Monthly salary    08.08.2010    09.08.2010    WIP    EdlinkHR    HR    Rec    Records    Ind    Induction Records    HRI.0001    Completion of dossiers.    08.07.2010    10.07.2010    WIP    EdlinkHR    HR &

application role how query a view whose reference table is in another db?

Hi everybody. I created  an application role in a database (DB1) and gave it all the rights on a view  in DB1 which refers to a table located in another db (DB2).  I also gave the rights to the app role on a table of  DB1 I tried to use this app. role through the sp_setapprole launched by a user  (server principal?) which is SQL Server administrator (and local administrator (Win 2003 Server)). With the following query SELECT USER_NAME() I see that the approle is being used. Than, if I query the table on DB1 everything works, but if I query the view, referring a table in db2 I get following error:   The server principal "NameOfServerPrincipal" is not able to access the database "DB2" under the current security context. What should I do to make it work? The table in DB2 has the same schema of the view in DB1 which refers to it. I put the DB1 TrustWorthy and both the database have the db_chaining option activated.   Any idea on how to solve the problem would be widely appreciated. Thank you very much. Vania

How to apply dynamic filter in Datasheet View from Query String

The datasheet view doesn't support either connections/dynamic filters from Query string. How to filter the data using query string?

How to avoid "'CREATE VIEW' must be the first statement in a query batch" when I need to use SET Q

I have a problem that I have been unable to solve.  I have a stored procedure in a database on server A that needs to create an indexed view in a database on server B.  (The environment is SQL Server 2005.)  The procedure on server A does the following:  (The EXEC statement inside the quotes is really a variable in my procedure, I've just substituted the value to make the example understandable.) EXEC sp_executesql 'EXEC [ServerB].[Database].dbo.sp_executesql @sqlStatement;' The "outer" sp_executesql causes the "inner" sp_executesql to be execute within the database on server B.  (@sqlStatement contains the CREATE VIEW syntax.)  I am able to create the view that I want to index with no problem.  However, when I attempt to create an index on the view in a subsequent step, it fails with the message "Cannot create index. Object '_dta_mv_51' was created with the following SET options off: 'QUOTED_IDENTIFIER'".  Fair enough, but if I attempt to precede my CREATE VIEW statement with the required QUOTED_IDENTIFIER, I receive an error to the effect that "'CREATE VIEW' must be the first statement in a query batch".  I'm not sure how to get around this problem.  Does anyone have the answer? SQL Server 2008 doesn't object to indexing a view that was created with QUOTED_IDENTIFIER

Problem with SELECT COUNT query and parameters

Hello!I have a problem with SELECT COUNT query in ASP.net. I want to create CMS with articles which have categories (which have the option to be deleted). The problem is that I want to get the number of articles within the specified category so if there aren't any articles with the specified category I can proceed with the category deletion.I have the following code:protected void Page_Load(object sender, EventArgs e) { } protected void GridViewKategorije_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Uredi") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow odabraniRed = GridViewKategorije.Rows[index]; TableCell ClanakID = odabraniRed.Cells[2]; string ID = ClanakID.Text; Response.Redirect("/Portal/Administracija/Kategorija.aspx?idKategorija=" + ID); } else if (e.CommandName == "Obrisi") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow odabraniRed = GridViewKategorije.Rows[index]; TableCell KategorijaID = odabraniRed.Cells[2]; String connString = WebConfigurationManager.ConnectionStrings["CMS"].ToString(); SqlConnection conn = new SqlConnection(connString); conn.Open(); using (SqlC

Dynamically fill query parameters in a table adapter ?

SO I have created an object data source on a page from a table adapter using the various Wizards in Visual Studio.Its meant to query a diary Database by a DateTime parameter called diaryDate. I want to query from a date Now to the next 14 days ahead.I want to display the entries in a Grid View when the page loads.So I'm a bit stuck now as to how to set the two query parameters date1 and date2. I want to set date1 = now() and date2 = now() + 14 days.How do I set those parameters when the page loads ?Should I have used the adapter Wizard approach of do I have to write all the code in the code behind page ??This is my datasource code'<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GET_nextTwoWeeks" TypeName="query_getNextTwoWeeksTableAdapters.diaryDatesTableAdapter"> <SelectParameters> <asp:FormParameter DefaultValue="" FormField="date1" Name="date1" Type="DateTime" /> <asp:FormParameter DefaultValue="" FormField="date2" Name="date2" Type="DateTime" /> </SelectParameters> <InsertParameters>

Adding a table or view multiple times when building a query with BI Report Designer and Report Build

How can I add a table/view multiple times to a single query by using BI Report Designer or Report Builder 3.0? In Report Designer I managed (workaround) to add one table multiple times by creating multiple Named Queries and having the same SELECT. Still I don't know how to add one table multiple times in Report Builder 3.0.

Can I drive a Grid View from more than one query ?


So Here's what I'm trying to do.

I have a Calendar Control on one page - the user clicks on a date and goes to another page which displays the details from a diary database for the selected date - works fine so far !

Now, whilst on that second page I want to give the User the choice of displaying all diary entries for the month, or for the year. So I could create a further 2 separate pages that display a GridView for a particular Month or a particular Year but that seems a bit of an over kill.

How can I make the Grid View display from different queries or maybe dynamically change the query depending upon whether a Month or Year is selected?

So my start page with the Calendar Control has this code:

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
        If Page.IsPostBack Then
            Response.Redirect("~/diaryPage.aspx?SelectedDate=" & Calendar1.SelectedDate)
        End If
    End Sub

After which the User gets taken to diaryPage.aspx with the Selected Date from the Calendar Control.

I then created a Table Adapter on the diary Page to query the diary Database with the Selected Date and drive the Grid View to display the details for that Selected Date.


Query with parameters in data flow



How can I run a query with parameters in a data flow task? I know I can use a script component and write code that executes the query, but I'm looking for a simpler solution, if there's such one.



Using query results as parameters

Hello all, i was wondering if there is a way of, only using tsql, solve this: i have a query that returns me a name of a column and i want to use that result like this: "Select (the_name_of_the_returned_column) from mytable"

Insert Parameters on a form View


Hi All

Are they any special Insert Paramters I shoud/need to use on a formView.  I currently have the below datasource but when submitted it only inserts <NULLS> intot he required table.

 <asp:SqlDataSource ID="addChangeDataStore" 
                                   ConnectionString="<%$ ConnectionStrings:LocalSQLServer %>"
                                   InsertCommand="INSERT INTO tblChanges(NINumber, TitleIDNo, Forename, Surname, ContractPostNumber, PayRef, DateofChange, TypeofChange, UserID, EmployerIDNo, FurtherInfo) VALUES (@NINO, @TitleIDNo, @Forenames, @Surname, @ContractPostNumber, @PayRef, @DateofChange, @TypeofChange, @UserID, @EmployerIDno, @FurtherInfo)" 
                                   SelectCommand="SELECT tblChanges.* FROM tblChanges">  
                                        <asp:Parameter Name="Nino" Type="String" ConvertEmptyStringToNull="true" /> 
                                        <asp:Parameter Name="TitleIDNo"  Type="String"  ConvertEmptyStringToNull="true" />

pass parameters to view


on my controller i have a "delete" logic after delete i want to redirect to Index view with proper message.
How do i pass it and how i show the message on the Index view?
 // POST: /Category/Delete/5

        public ActionResult Delete(int id, FormCollection collection)
                // TODO: Add delete logic here

                var cat = db.categories.SingleOrDefault(x => x.categoryId == id);

                if (cat == null)
                    return View("NotFound");
                    ViewData["Message"] = "Category was deleted";
                    return RedirectToAction("Index");  
                ViewData["Message"] = "Error on delete Category";
                return RedirectToAction("Index");  
                //return View();

and my Index
public ActionResult Index()
            // var cat 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend