DataSource Controls :: Not Able To Run SQL Query Using If Else?
Apr 21, 2010
I am using Querystring "ddl4" to pass on value of a drop down list to the next page where I am using that value in the WHERE clause of a SQL command. I also need to check whether ddl4 is blank or not which I do using If Else in SQL command. I am not able to run the query where the Querystring ddl4 IS NULL
This is the sample link with the Querystring ddl4 carrying a blank value:
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.
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.
Dim MediaQuery = From m In dB.DOWNLOADS _Where m.ID = id _Select
which returns a record from the database. One of the fields in the record is a FK to another table. I need to read this value to be able to set a dropdown based on the ID but I can't work out how to access it. For a standard record I can just do the following txtTitle.Text = MediaQuery.FirstOrDefault().TITLE
However with the foreign key it doesn't work like that. I've tried drpGroup.SelectedIndex = MediaQuery.FirstOrDefault().DOWNLOAD_GROUPS.ID where DOWNLOAD_GROUPS is the FK field but it returns Object reference not set to an instance of an object. If you're simply wanting to read some values from a single db record in the entitiy framework and one is a foreign key how should I go about getting the value?
I have one query in my project (saved in folder SQLQueryes, Query.sql) and i need to execute it. Also, i have one parameter in script and i need to include him also. How?
i want to know that should first name and last should be kept as sperate field or merged into single attribute. The Basic problem i am facing to keep first name and last name in seperate fields is that i cannot effectively use like query for searching a record by name
I'm creating a web project in ASP.NET (C#) using Visual Studio 2010. I'm using the built-in login page. Here is what I'm trying to achieve.I want when a user logs in, the default.aspx page will display all his information including firstname, lastname, email address... I created a database table to store all users information (SQL). I want to use the "login name" as a parameter in "SELECT * FROM usertable WHERE username = loginname". From the code-behind (default.aspx.cs) I can pull the current loginname with "this.User.Identity.Name" but I can't pass this information to the query command in the default.aspx page.For example, when Jim logs in with his user name as "sirjim", I want to use"sirjim" in place of "loginname" in default.aspx page.Code in default.aspx page:
Table1 - user master table. table2 - transaction table. Now I want to write a single query which will give results like table 3. how to write single query.
I have several dropdowns in ASP.net, I want the contents in each dropdown depending on what is selected from the above dropdown and the datasource queries reflect this. I have the queries correct for the first two dropdowns, but I cannot get the third displaying data.
The first dropdown just contains all dept names
The second dropdown contains the manager names in that chosen dept above
The third is meant to contain the list employees relating to the chosen manager name above
I am having some trouble querying a SQL Express DB from my ASP.NET 3.5 application. I am new to ASP.NET 3.5, only having used ASP in the past.In ASP, my code would be:
Dim db Set db = Server.CreateObject("ADODB.connection") 'Opens the db connection string stored in another asp webform [code]....
This code creates the connection to the database, assigns the variable SQLi with the query, and assigns the execute command for that query to the variable RSi.
In ASP.NET, I have managed to get this far:
'The connection string is stored in web.config [code].....
I am unsure how to do the next part, when the individual id is assigned to the variable GEN1i (the syntax .fields does not appear to work for me).
I want to use from two db connection in one linq query
My sample is:
int a=1; if(a==1) DataClasses1DataContext1 db = new DataClasses1DataContext1(); else DataClasses1DataContext2 db = new DataClasses1DataContext2(); var q = from c in db.F_Groups select c;
In this code a=1 so db connection is DataClasses1DataContext1
I want if a=2 then db connection = DataClasses1DataContext2
but this code is error.
db connections is completely same but in two deferent class a db connection is sql and another is oracle
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)
in DataBase Attendancedate is save in this format 4/5/2010 4:16:28 PM ..i want to query like this select * from EmployeeAttendance where Attendancedate='4/5/2010' but this giv error
declare @stateQuery as nvarchar(200) if @stateid is null set @stateQuery='' if @stateid is not null set @stateQuery='and tbl_city.stateid ='+cast(@stateid as nvarchar(10)) set @length=(select top 1 len(dbo.Tbl_city.cityName) FROM dbo.tbl_city INNER JOIN tbl_cityinfonew ON dbo.tbl_city.cityId = tbl_cityinfonew.cityId where (tbl_cityinfonew.language =@language )+cast( @stateQuery as nvarchar(100)) order by tbl_cityinfonew.createdate desc)
I am using a data list to display some value retrieved from a SQL query. My problem is that I would like to insert a variable for the field of ISDS_454.dbo.booksusers.userID. The variable has already been declared and stored upon page load. I just need some way to get it within the SQL query for the datalist.
<script runat="server"> Sub Page_Load() Dim ID As String = "D07AD7E0-8E34-4C18-9B4D-10576B0CC6BF" End Sub </script> <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate> fic: <asp:Label ID="ficLabel" runat="server" Text='<%# Eval("fic") %>' /> <br /> <br /> </ItemTemplate> </asp:DataList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ISDS_454ConnectionString %>" SelectCommand="Select COUNT(*) as fic From ISDS_454.dbo.Books, ISDS_454.dbo.booksusers, ISDS_454.dbo.Genre where ISDS_454.dbo.Books.ISBN = ISDS_454.dbo.booksusers.ISBN And ISDS_454.dbo.Genre.Genre_ID = '1' And ISDS_454.dbo.booksusers.userID = 'D07AD7E0-8E34-4C18-9B4D-10576B0CC6BF'"> </asp:SqlDataSource>