C# - Conditional Statements Difference?
Feb 10, 2011Is there any difference between below two statements
if (null != obj)
and
if (obj != null)
Edit: if both treated same which will be preferable?
Is there any difference between below two statements
if (null != obj)
and
if (obj != null)
Edit: if both treated same which will be preferable?
I'm using the 'Configure Data Source' wizard to connect to my database and show the dataset in Gridview. I want to be able to update, insert and delete entries but am unsure how to build the query. I can write simple update statments to change database entries but how can I do this for entries that have been changed within the gridview?
View 6 RepliesThis might be confusing but ill try to explain the best as i can. I have a gridview that get the data from datatable. This is simulation my grid view.
key data
1 data1
2 data2
2. data2
2. data2
3. data3
3. data3
what i want is make some conditional statement, when value "key" is changed i want to add empty row. so its suppose to be looks like this as result.
key data
1 data1
EMPTY ROW
2 data2
2. data2
2. data2
EMPTY ROW
3. data3
3. data3
string sqlstring =
"SELECT DISTINCT STAFF_ID, SCHOOL_CODE FROM MODULE_TIMETABLE_STAFF WHERE STAFF_ID != '" +userId +
"' AND STAFF_ID LIKE '%" + Searcht +
"%' ORDER BY STAFF_ID ASC";
can anyone explain this statement for me? especiallythese signs !=,+ +
I want to add Sum contents from the two tables, Realize the rows could be different, Only like rows to be added rest of the rows from both tables are listed.
SELECT TYPE AS CashFlow, Sum(AceData.InCredit) AS Credit, Sum(AceData.OutDebit) AS Debit, Sum([InCredit]+[OutDebit]) AS Totals
FROM AceData
where case=1
GROUP BY Type;
CashFlow Credit Debit Totals
Advert $0.00 ($5,816.52) ($5,816.52)
BOND $0.00 ($3,060.00) ($3,060.00)
Cash $18,619.57 ($34,824.75) ($16,205.18)
Charity $0.00 ($6,578.00) ($6,578.00)
DayCare $0.00 ($2,360.00) ($2,360.00)
SELECT TYPE AS CashFlow, Sum(AceData.InCredit) AS Credit, Sum(AceData.OutDebit) AS Debit, Sum([InCredit]+[OutDebit]) AS Totals
FROM AceData
where case=2
GROUP BY Type;
CashFlow Credit Debit Totals
BOND $0.00 ($3,060.00) ($3,060.00)
Cash $18,619.57 ($34,824.75) ($16,205.18)
Charity $0.00 ($6,578.00) ($6,578.00)
DayCare $0.00 ($2,360.00) ($2,360.00)
Entertainmen $0.00 ($12,258.18) ($12,258.18)
Equipment $0.00 ($7,085.00) ($7,085.00)
Fee $1,957.63 ($27,611.85) ($25,654.22)
How can I schedule several statements that involve select ... into ..., delete, and exec one other stored proc, periodically? For instance, every 6 hours, in Sql server DB
View 1 Repliesi want to execute more than one query in a page.i tried to use sqlreader it didnt allow me to include.how to do ?This is my code.
[Code]....
this is how i did.it shows me error.how to solve this error?
I'm using MySql in my asp.net project. But I don't want to type every "using MySql.Data.MySqlClient;" statement in every aspx.cs/aspx.vb file. How can I define this lines in web.config file?
I've defined some namespaces like below but this only works for aspx pages:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0"/>
<pages>
<namespaces>
<add namespace="System.Web.Configuration"/>
<add namespace="MySql.Data"/>
<add namespace="MySql.Data.MySqlClient"/>
</namespaces>
</pages>
</system.web>
</configuration>
related question : Define common namespaces for code pages in Web.Config
how to join 2 sql select statements in Oracle, which has different number of rows. That is I have first select statement which fetchs around 80 records in below format.
DATE MONEY
12-01-2010 10
12-01-2010 15
12-01-2010 15
12-02-2010 15
12-02-2010 15
12-03-2010 15
12-03-2010 15
Second statement will give reocrds like below. That is it will give only distinct dates. Please tell me how to join these two queries. So that I can get
DATE Rank
12-01-2010 a
12-02-2010 b
12-03-2010 c
how to join these two queries. So that I can get result set in below format.
DATE MONEY Rank
12-01-2010 10 a
12-01-2010 15 a
12-01-2010 15 a
12-02-2010 15 b
12-02-2010 15 b
12-03-2010 15 c
12-03-2010 15 c
I've got a repeater on my asp.net (VB):
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Question_Number") %>' />
<%#Eval("Question_Desc")%>
Now what I want to do is, check a value that I haven't used called "Question_Type" which could be = 1, 2 or 3 depending if it is multiple choice, short answer, etc. I have tried this:
<%
if Eval("Question_type") = 1 then
Response.Write(" <asp:RadioButton runat=""server"">test1</asp:RadioButton>")
Response.Write(" <asp:RadioButton runat=""server"">test2</asp:RadioButton>")
Response.Write(" <asp:RadioButton runat=""server"">test3</asp:RadioButton>")
end if
%>
and I get this error: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. HOW can I use this value in a if statement?
I have a ListView with many advanced controls and html tags. ListView is bound to collection of profiles when first profile in collection is current profile. current profile has few differences from other profiles ie. flash embed, js and some other stuff. I can access inside of my ListView Container.DataIndex property which gives me 0 as first item in index but i'm unable to use inline If statements like so
<% If Container.DataIndex = 0 Then %>
do stuff
<% EndIf %>
this is because i must place pound to access databound item but neither this
<%# If Container.DataIndex = 0 Then %>
do stuff
<% EndIf %>
How can i make inline If ?
I am trying to put a Right Outer Join on Linq statements. how to put Right Outer Join on Linq.
View 1 Repliesi would like to retrieve a value with select and perform a calculation and then save using update in the same batch code?
View 3 RepliesMulti-Token Statements
The @( ) syntax enables a code block to have multiple tokens. For example, we could re-write the above code to concatenate a string and the number together within a @( code ) block
Will there be support for shorthand statements?
Example:
[Code...]
as apposed to;
[Code...]
perhaps ternary opperators?
What is the best way to prevent deep nested statements. I'm looking at a piece of code which is 7 statements deep, and it is massively un-readable!
View 3 RepliesI have a BasePage class that all of my content pages inherit from. In my BasePage, I have many Import Statements. It seems as though they carry over into the derived class as one would expect. However, if you were to try and access code in the client aspx design page, as you would in the code-behind, you run into problems.
For instance, in my BasePage i have a Public Enum named ThemedSites. It's just an enumerator that lists the 5 different themes my site could be skinned as. I, at times, need to do different things in code, and in design, depending on what theme I'm currently in. I have a Public Property named CurrentSite (might have been more appropriate to say CurrentTheme, but that's besides the point). CurrentSite's return type is ThemedSites. So in code, one would say something like:
[Code]....
This works great in any page that inherits the BasePage class. This falters when that very same logic is used in the design page like:
[Code]....
Now, it works if you fully qualify both sides of the condition, but that's not my question. My question is: why isn't the Imported NameSpace in the BasePage recognized in the client-side server tag, as one would think it would be, according to how it IS recognized in the server-side code-behind?
I am facing an intresting problem now with entity framework. if i did a count of the some table with linq statement its give some count and it is not matching with my normal sql query count. my sql query returning count of all the records in that table where as linq query returns some count which is less than sql count. is this a problem with my edmx or table navigation properties..i do have some 5 to 6 child tables inside this table with foreignkey relation. will it do a join on each child table and returns only those records. I am very much confused and don't know how to slove this.
View 9 RepliesIs there any design pattern or architectural design that prevent the following type of code, where I have an enum with different fileformats and I have to make a switch anywhere I want to distinguish between the different fileformats?
[Code]....
If add an item to the enum definition in this case I have to change all the code that uses switches and that kind og enum which, I guess, is a bad approach in terms on maintenance of the application?
I have an ASP.NET GridView which displays a list of neighborhoods.
I wish a user (administrator) to be able to edit the neighborhood name.
Now, the database is quite complex, and as such, i can't simply provide an UpdateCommand / SqlDataSource for the GridView.
I bind the data manually (on first load, and on the PageIndexChanging event).
Binding/listing paged data is working fine.
However, i'm having trouble trying to UPDATE the data.
The user clicks the "Edit" button, the textbox for the neighborhood name is shown, i change the text, click "Update", but the RowUpdating event is not firing.
I basically want to grab the row that was edited, and perform a custom update using LINQ.
Is this not possible with a GridView? If it's not, what are my alternatives? A repeater with LinkButtons and a hidden textbox that can swap in/out the labels?
This is my GridView markup:
[Code]....
And the code-behind:
protected void NeighborhoodsGridRowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow updatedRow = NeighborhoodsGrid.Rows[e.RowIndex]; // not firing. =(
}
I also have the GridView wrapped in an UpdatePanel, if that makes any difference (don't think it should).
I'm updating my old .aspx views with the new Razore view engine. I have a bunch of places where I have code like this:
<span class="vote-up<%= puzzle.UserVote == VoteType.Up ? "-selected" : "" %>">Vote Up</span>
Ideally I'd like to do this:
<span class="vote-up@{puzzle.UserVote == VoteType.Up ? "-selected" : ""}">Vote Up</span>
However there's two problems here:
vote-up@{puzzle.UserVote .... is not treating the @ symbol as a start of a code block @puzzle.UserVote == VoteType.Up looks at the first part @puzzle.UserVote as if it's supposed to render the value of the variable.
I know how to do this with 1 declare statement, but for this there are multiple one's. This example sql statement has 2, however my actual one will have 29.
[Code]....
look at the following code
[Code]....
The last three statments produces the same effect. Which one is better and mostly used?
In order to get Database.Open("sdfsdf"); to work in one of my MVC3 .cshtml pages I had to add a using statement at the top of the page.@using WebMatrix.Data.I added it to the Web.Config file under the <pages><namespaces> section and it didn't work.
1. Do .cshtml pages not respect that section in the web.config? If not
2. Do we need to add @using statements in every page? Or is there a better way?
I can't get helpers like @LinkShare.GetHtml and @Gravatar.GetHtml working despite have references to:
System.Web.WebPages
System.Web.Helpers
And adding @using statements.
3. What am I missing in order to get the helpers working in my MVC3 project?
I am new to asp programming and have inherited an old website that was connected to an SQL 2000 server. The SQL 2000 server is being retired and replaced with a SQL 2008 server. We moved the DB to the new 2008 server with no problems. However the web site does not function (Database Connection error). I believe the problem is with the old asp code being written for mySQL vice SQL. It may have worked on SQL 2000 but it does not seem to work on SQL 2008.. The code is below:
<%
function write_it(mystr)
if not isnull(mystr) then
[code]...