DataSource Controls :: Null Option In Qurery Parameters / Using Query With DropDownList And Textbox Controls?
Dec 18, 2010
I have SqlDataSource with a few parameters (code below). If I understand this code correctly if parameter is NULL I should receive all items from the query. It works fine with query editor. But when I try to use this query on my page - with DropDownList and Textbox controls as source of parameters - it doesn't work. I suspect that main reason of problem is value which these controls pass to the query. Instead of NULL this is an empty string. Is it possible to pass NULL value from DropDownList or TextBox to
the SqlDataSource?
here is my code for selectiong some records from db table
string strSql = "select * from mtblNBD where SentTo=@SentTo and InternalStatus Is NULL order by DeadLine desc"; SqlCommand com = new SqlCommand(strSql, con); com.Parameters.Add("@SentTo", SqlDbType.NVarChar, 50).Value = (string)Session["uname"];
here I am using parameters for SenTo field but not for NULL so it is ok... or should I use parameters for this field where value is NULL , if yes then how can I use parameter for this
When user selects 10 miles from dropdownlist DDL1 and types AAA20 in textbox1 which is of type text, on button click it has to pull all the columns from database and show results in gridview using sqldatasource store procedure. I'm stuck in server side code..how to pull the data..in store procedure I'm passing two parameters val1 and val2. val1 gets data from DDL1 and val2 gets data when user types in textbox1 and it has to validate the text...see the code below mentioned and tell me how to pass the params and get the data in gridview...
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 have a FormView which is bound to an SQLDataSource. When a user clicks on a save button the form, I need to write any changes made to the FormView back to the table.
I have a Stored Procedure on my MSSQL 2005 database that should be executed when the user clicks on the save button.
It appears the Update is firing, but when I trap the DbCommand object in the SQLDataSource's 'Updating' event, all of the parameters that should be passed to the Stored Procedure are coming through as NULLs. Consequently, the Stored Procedure isn't updating anything.
In the click event of the save button I'm explicitly firing the SQLDataSource's Update method:
[Code]....
The parameters in the SQLDataSource <UpdateParameters></UpdateParameters> section appear to be correct.
Can anyone give me an idea on what to investigate to figure out why it appears the Update is only picking up NULLs?
with query parameters in ASP.NET. For example, if I have query:
[Code]....
for parameter @id I intend to use combobox. Everything is just fine with this example, problem begins when I try to use IN clause.What I need is query like this:
I am creating a TableAdapter using corresponding wizard, with a GetDataByID() query. The select statement is like this:select * from books where ID = ?Thus books are filtered by ID. But in case a null is passed as a parameter, I want to select all records rather than none. Could you please tell me how I can do it?
here is my query which is not working properly. I have 5 fields in my table Company, Reseller, Item, Code, Price. How can i get minimum Price when i pass parameters for Code is dublication value
Company Reseller Item Code Price A A-1 I1 C1 20 B A-21 I2 C2 13 C A-B I1 C1 19
select Company,Reseller,Item,Code,Min(Price) from Table1 where code='C1' order by Code HOW CAN I GET THIS BELOW TYPE OF RESULT
Company Reseller Item Code Price A A-1 I1 C1 20 C A-B I1 C1 19
Trying to add another 2nd dropdownlist to Query String... Below This Query String works Perfectly:
Query = String.Format("SELECT {0} FROM {1} WHERE NACategory = '{2}' ORDER BY {3}", PrimaryKeyColumn, TableName, DDLCategory.SelectedItem.Text, SetSorting()) I've tried to add a 2nd DDLSubCategory.SelectedItem.Text - But its throwing and error message. Exception of type System.StackOverflowException was thrown. Query = String.Format("SELECT {0} FROM {1} WHERE NACategory = '{2}' AND NASubCategory = '{3}' ORDER BY {4}", PrimaryKeyColumn, TableName, DDLCategory.SelectedItem.Text, DDLSubCategory.SelectedItem.Text, SetSorting()) Can Someone take a look I'm not sure how to write (add) 2nd DropdownList (DDLSubCategory.SelectedItem.Text)
I have dropdownlist of dates and depending on the date that the user selects from list, I would like to filter records that fall between the startyear and finishyear columns in the datasource. (My the problem is that I do not know how to declare the Startyear and Endyear from the query in the code as they appear underlined - probably the BETWEEN syntax is wrong too).
yYear = DropDownList1.Text Using connection As New SqlConnection("Data Source=CHRIS-PCSQLEXPRESS;Initial Catalog=TorGHL;Integrated Security=True") Dim cmd As String cmd = "SELECT BarDetails.*, MenuHeadingId AS Expr1 FROM BarDetails WHERE (MenuHeadingId = 2)" & "WHERE " & yYear & " BETWEEN " & "(" & StartYear & ")" & " AND " & "(" & EndYear & ")" connection.Open() Dim dapubcb As New SqlDataAdapterDim sqlcomm As New SqlCommand(cmd, connection) dapubcb.SelectCommand = sqlcomm Dim dspubcb As New DataSet("BarDetails") dapubcb.Fill(dspubcb, "BarDetails")
I've been reading up on SQL Injection and want to go back and implement some measures to prevent these kinds of potential attacks.For example, on our company intranet, we have an address book feature and a search function so the user is able to look a company or a person up from the database/The user will enter their query into a TextBox control and click the Submit button, calling the following function:addybookDS1.SelectCommand = "SELECT * FROM [addressbook] WHERE COMPANY LIKE '%" + search1 + "%' OR CONTACT LIKE '%" + search1 + "%' OR LASTNAME LIKE '%" + search1 + "%' OR EMAIL LIKE '%" + search1 + "%'"search1 is the TextBox controlI had previously implemented this measure:search1 = Replace(search1, "'", "''")But I want to know if there is more I can do here and how I can go about doing it.
I've been trying to find a solution to my problem for about 2 days now, and have found nothing. I am new to .net and not really sure how to accomplish this. I have 4 tables in a database, Vendors, RepairCos, Cons, ConRepairHistory. What I'm trying to do is make a page called SendOutForRepair.aspx that has a insert item template where the first control is a dropdownlist that is attached to the Cons table (got this figured out) and is populated with the Serial Number field. I would like the selection from the dropdownlist to populate the 2nd control (VendorID) that is also from the Cons table....
Can i get a multiselect dropdownlist with option to select all and select none. I need it urgently....please send the control to arup.bhattacharya@[URL].
How do i make the default entry in a dropdownlist not selectable? Right now I have a drop down and the users are able to select the default option that says (Select one)...here is what my code look like. I hard coded my options in there cause the list is really short and won't change ever. Right now, users can select the default entry and add it whatever list they are generating on the page...and I would like to make that default visible but not selectable.
I have a data grid with a lot of information on it - to easily filter the data, I would like to be able to pass parameters to it. My problem is that I do not want the parameters to be required. So if I just put 1 or 2 of them in the query string, I would like for it to return all of the data related to those two parameters.I am using a data grid & stored procedures:My Stored Procedure looks like this:
i have one table and structure of table is like.Now i need to fetch the Resturant Name and status of Resturant ( whether it is closed or open by comparing the opening time and closingTime with currentTime).
By right clicking on my database i created a query in server explorer. But where are this query stored can't find them back. I should aspect that their is a folder query's like there is a folder tables but this isn't the case.