July 18, 2017 at 6:20 am
In my asp.net project, I need to code to select a data from a stored procedure and then bind to a grid.
Since I did not have permission to modify the stored procedure, how to add where clause to select data from the result of stored procedure?
For example, the result of the stored procedure may return 10000 records but for my project, I only need to select "where city='London'".
How to complete it?
July 18, 2017 at 6:31 am
adonetok - Tuesday, July 18, 2017 6:20 AMIn my asp.net project, I need to code to select a data from a stored procedure and then bind to a grid.
Since I did not have permission to modify the stored procedure, how to add where clause to select data from the result of stored procedure?
For example, the result of the stored procedure may return 10000 records but for my project, I only need to select "where city='London'".
How to complete it?
Can you create an new procedure or have one created for you?
😎
Another option would be to build the query in your code.
July 18, 2017 at 6:35 am
If you're stuck with the stored procedure as it is, you can insert the results into a temp table and select from that.
John
July 18, 2017 at 6:35 am
No, this stored procedure is coming a product purchased by company.
July 18, 2017 at 6:56 am
Are you returning the dataset into a datatable? If so, you can filter these. In VB, I think the syntax would be something along the lines of:Dim sqlConn As New SqlConnection(connString)
Dim sqlComm As New SqlCommand("dbo.your_SP", sqlConn)
sqlComm.CommandType = CommandType.StoredProcedure
'Add a random parameter, in case you have those '(extra single quote cause of the silly code interpreter on SSC :( )
sqlComm.Parameters.Add(New SqlParameter("@CompanyID", SqlDbType.Int))
sqlComm.Parameters("@CompanyID").Value = 1
Try
sqlConn.Open()
Dim rs As SqlDataReader = sqlComm.ExecuteReader
Dim dt As DataTable = New DataTable
dt.Load(rs)
Dim dr() As DataRow
'This is your filter '
dr = dt.Select("Location='London'")
dgvSales.DataSource = dr
Catch Ex as Exception
Messagebox.Show (Ex.Message)
Finally
sqlConn.Close()
End Try
Disclaimer: This is untested, and i am working from memory. This code will likely need some kind of amendment. If your application is in C# you will need to translate, I can't write the language (sorry).
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
July 18, 2017 at 7:02 am
adonetok - Tuesday, July 18, 2017 6:35 AMNo, this stored procedure is coming a product purchased by company.
Can you copy it to make a new procedure?
July 18, 2017 at 9:26 am
The stored procedure is locked can't open.
July 19, 2017 at 3:46 am
What does your code look like now? You can use Linq on DataTables as well (or on any IEnumerable if you are not using DataTables)
e.g. (from Stack Overflow)
var result=myDataTable.AsEnumerable().Where(myRow => myRow.Field<string>("Location") == "London");
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply