Search Database Returning Results To Gridview Via Sqldatareader?
Feb 23, 2010
I am trying to create a search page, this allows the admin to search through the entries in the database by certain criteria, such as province (like state but diff country)
Here is the code I have so far. The problem is that I am not getting any errors. But I am also not getting any results. The page just posts back and returns to the blank search page. The GridView does not display any results.
here is my code as it stands:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration
Partial Class administration_Search
Inherits System.Web.UI.Page
Protected Sub ProvinceButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ProvinceButton.Click
'get the search string from text box
Dim Search As String
Search = ("%" & ProvinceButton.Text & "%")
'if the string has value then continue with search
If Len(Trim(Search)) > 0 Then
Dim con As String = WebConfigurationManager.ConnectionStrings("fubar").ToString()
'build sql string
Dim s As String
s = ("SELECT id, surname, name FROM orders WHERE province like @strSearch")
'declar connection
Dim c As SqlConnection = New SqlConnection(con)
'add command
Dim x As New SqlCommand(s, c)
'add parameter
x.Parameters.AddWithValue("@strSearch", strSearch)
c.Open()
Dim r As SqlDataReader = x.ExecuteReader
GV.DataSource = r
GV.DataBind()
c.Close()
Else
Province.Text = ("Please enter search terms")
End If
End Sub
End Class
On the .aspx page I have a textbox (id: province) and a button (id:submit)
In my web form I have a search box. The user enters a string, and once the search button is clicked, I pass the value from my .js file to my .cs file and do some processing to get the results. Up to this point everything is fine, but now I dont know how to get my results back to my .js page. The serach results at this point are in a dataset, and also in an multidimensional array. I have a multi array because I need to pass back the code and description of the items found.
[Code]....
At this point I have used the passed string 'value' to get my required code/descriptions, but i'm not sure how/if I can get either the Dataset or multidimensional array back to my .js page
I need a query to fetch records from data from database based on partial text entered in textbox like search data from College table based on College Name entered in text box. I want that all record containing that College name displayed in grid view.
Gridview is not being populated now that i built my objectdatasource in the code behind.. why. If i build the source on the aspx page and configure it that way, it returns results.. but when i try to build it in the code behind it just displays my empty template for the gridview.
I am trying to run a stored proc from this function. When I run it thorugh the debugger I can see that myReader.HasRows = true and myReader.FieldCount =14.
But the control does not go in the loop while (myReader.Read()) where I am trying to read Version field returned by the stored proc.
Using Visual Web Developer I have created a page (Search.aspx) with a Text Box(SourcingIC) and Search Button. I do not want data (Gridview) displayed on the Search.aspx page, just the Text Box and Search Button.
A user inserts name in the text box(SourcingIC), presses the search button and then is directed to a new page (SearchResults.aspx) that displays the records found for SourcingIC. What coding is needed to make this happen? Can you provide me with what actual coding would need to be added?
I am trying to develop a page where I am trying to search a database (MyQSL) and display the data in a table format. Some of the database entries, like category, is stored as integer values, but I want to display the category name in the search result (not the corresponding integer value). I have also another issue, every time I change the dropdown list values (which are having "auto postback" enabled) the <EmptyDataTemplate> is returned. At this moment I am using GridView. But I am ready to change this to any other method, like repeater or whatever...
I want to search record based on Name, ID, Date, Report Type. from same table with one textbox. I can do search with one column how can do it with multiple column ...
protected void Button2_Click(object sender, EventArgs e) { DateTime dt = Convert.ToDateTime(TextBox1.Text); SqlCommand cmd = new SqlCommand("SELECT * FROM Transactions where report_type = @report_type "); cmd.Connection = con;
I'm developing a search page that will display the results in a gridview. The codebehind (in VB.NET) uses a SQL command to fill the gridview.
The gridview does have paging and sorting enabled. Once the search button is clicked the initial results are displayed, if the user clicks on a sorted column or wants to advance a page the gridview disappears. Enable Sorting And Paging Callbacks is set to True. Enable ViewState is also set to True.
I would like a gridview (using entitydatasource) to display the search results based on values provided in textbox txtSearch and dropdownlist ddlsearch. My search controls are as follows:
[Code]....
My entitydatasource is:
[Code]....
My gridview is written as:
[Code]....
Codebehind file contains:
[Code]....
I am a newbie at entitydatasource and have a few questions:
1. Currently, the gridview doesn't render. Why is that?
2. How do I wire up the gridview to grab the values of ddlsearch and txtSearch and return results using those values from my entitydatasource?
3. Ultimately, I want to encapsulate this gridview in a wizard step wherein the user checks items they want and those checked items are used in the next wizard step.
I have a .net page in which i have a search button which populates the data in gridview. On Headder row of gridview i have a filter image button and when user clicks on it i need to have a div tag opened as popup and in which i have to load the data of first column data of grid view as list of checkboxs and when user clicks one by one the parent gridview need to be shortened out (reduce) basing on selected/checked item in div tag. Since the check box controls are added dynamically it need to happen in Page_PreInit, so what i am trying to do is on the search i am trying to post back the page which goes to the Page_PreInit and tries to create all these check boxes dynamically.
I am trying to export a gridview that is returned from a search form. The gridview also has paging enabled. In order to export the records from all pages in the gridview I had to turn off paging and do a databind, but instead of only exporting the search results it exports all the records in the gridview.
How can I only export the records from the search results, but also the make sure the records on the different pages export also?
As a newbie coming from a Java background with tag libraries I wonder if there is a simple possibility to render areas depending on backend values.For example if I have search form I do not want to render the table for the search results as long as the user hasn't pressed the search button. Of course I can iterate over the model containing an empty list but this does not allow to suppress rendering the whole table.Using web forms I would just control the visibility of the affected tag(s) in the code behind file but how do I do this with ASP.NET MVC?Can I use a partital view for a case like this? But I think I would have the same problem. How can I determine if a partial view is rendered (e.g. the whole result table with header)?
i have some text boxs in a page and in the same page there will be a table 'grid' like for holding the search result.When the user start editing and of the textbox above, the search must start by sending all textboxs values to the server 'ajax', and get back with the results to fill the below grid.
Notes:This grid should support paging, sorting by clicking on headers and it will contains some controls beside the results such as checkboxs for boolean values and links for opening details in another page.
I know many ways to do this some of them are:1- updatepanel around all of these controls and thats it "fast dirty solution"
2- send the search criteria using ajax request using JQuery post function for example and get back the JSON result, and using a template will draw the grid "clean but will take time to finish and will be harder to edit later".
3- ....My question is:What do you think will be the best choice to implement this scenario? because i face this scenario too much, and want to know which implementation will be better regarding performance, optimization, and time to finish.
on the form i have one dropdown and search button. Accroding to selected value of dropdownlist, on pressing search button user will see results in gridview.now in after the result is shown and user selects say page 2 then results are shown of page 2. But then if i select new dropdownlist value and press search, it shows result but directly goes to page 2(last time's page selected) instead of showing page 1....
The SQL is below - each result is coming up 3 times rather than just once.
SELECT Consignments.LegacyID, TripDate, CollectionName, DeliveryName, Pallets, Weight, BaseRate, Consignments.FuelSurcharge, AdditionalCharges, BaseRate * Quantity AS 'InvoiceValue', Consignments.Customer, InvoiceNumber, CASE WHEN child.LegacyID = Consignments.Customer THEN child.LegacyID WHEN parent.LegacyID = Consignments.Customer THEN parent.LegacyID ELSE this.LegacyID END AS 'InvoiceAcc' FROM SageAccount this LEFT JOIN SageAccount parent on parent.LegacyID = this.InvoiceAccount LEFT JOIN SageAccount child on this.LegacyID = child.InvoiceAccount JOIN Consignments on (Consignments.Customer = this.LegacyID AND this.Customer = 'True') OR (Consignments.Customer = parent.LegacyID AND parent.Customer = 'True') OR (Consignments.Customer = child.LegacyID AND child.Customer = 'True') WHERE (this.LegacyID = @Customer) AND (TripDate BETWEEN @fromdate AND @todate) AND (InvoiceNumber IS NOT NULL)
The SQL was given to me for another similar query, but this time I have modified it to try to use it for the query I'm doing now, so I'm assuming that I'm doing something stupid.
I have a query using LINQ-to-SQL. It queries an underlying database table Rooms. It uses Where conditions to narrow down the results, namely:
Gender. Current Occupancy < Max Occupancy Available Flag is Checked
I know this should return results but it keeps returning an empty set. Any ideas? Code is below
Dim selectedHalls = (From sh In dbHalls.Rooms _ Where sh.gender = Session("gender").ToString _ Where sh.max_occupancy > sh.current_occupancy _ Where sh.is_available = 1 _ Select sh.building_name).Distinct()
UPDATE: I've verified that the issue is with the statement where sh.is_available = 1, which doesn't make sense since this is a bit field.
I am hoping someone can point me in the right direction here. I am trying to create web service that will return ajaxified results. Specifically, I want to write a web service that will fetch email through a secure connection. However, rather then have the web service return every single email, I just want to fetch maybe 5 emails at a time. I've always used Ajax as a client helper technology and not sure how to go about implementing this on a server side, or if its even possible.
Edit: I solved my problem but if you have anything to add do. Note: I did not create the DB it was created by Wordpress hosted on GoDaddy with my site I have a MySql Database called "wordpress" (for clarity). I want to be able to grab the most recent post from my blog and show it on the landing page for my url. So my thought is this: connect to the MySql DB, run a query to grab the most recent post, display the post.
I built a class to handle the connection and process the request:
public class DAL { private string connectionString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=[server here]; PORT=[port]; DATABASE=wordpress; USER=[user name here]; PASSWORD=[password here];"; private OdbcConnection blogConnection;
I have a procedure that is used on a search page.. im trying to provide a highlevel resultset which you can then click on a record to view all records associated with it.
My expectation is to return 5 columns.. the ID and Date is what i want to group on.. so that if there are 10 records for ID=5 and Date=10/25/2010 then in my results i would have 1 record. Once im done with the page, you can then click on that line in the gridview to view the 10 records for that id. Does that make sense?
I have the following query, but for the criteria i entered, im getting back 3 records instead of just 2 since there is a differnet reboot count, BUT i really still just need overall data. so it should be only 1 record and seen below is what is returned and what is expected..
I'm having an issue with SSRS 2008 inside VS 2008, where I have a report that is connected to the database via a Data Source which is working correctly, but when I execute a query inside the query designer to test my data, it returns zero records.
The issue I'm having is that the EXACT same query inside SSMS returns the correct record. I'm really stumped as to why it all is connected, but not returning the record. I have another report in the solution that uses the same database, but that one actually works ok.