Search Results

Search found 6988 results on 280 pages for 'if else statement'.

Page 39/280 | < Previous Page | 35 36 37 38 39 40 41 42 43 44 45 46  | Next Page >

  • sql rowlock on select statement

    - by David
    I have an ASP.Net webpage where the user selects a row for editing. I want to use the row lock on that row and once the user finishes the editing and updates another user can edit that row i.e. How can I use rowlock so that only one user can edit a row? Thank you

    Read the article

  • is it better to test if a function is needed inside or outside of it?

    - by b0x0rz
    what is the best practice? call a function then return if you test for something, or test for something then call? i prefer the test inside of function because it makes an easier viewing of what functions are called. for example: protected void Application_BeginRequest(object sender, EventArgs e) { this.FixURLCosmetics(); } and private void FixURLCosmetics() { HttpContext context = HttpContext.Current; if (!context.Request.HttpMethod.ToString().Equals("GET", StringComparison.OrdinalIgnoreCase)) { // if not a GET method cancel url cosmetics return; }; string url = context.Request.RawUrl.ToString(); bool doRedirect = false; // remove > default.aspx if (url.EndsWith("/default.aspx", StringComparison.OrdinalIgnoreCase)) { url = url.Substring(0, url.Length - 12); doRedirect = true; } // remove > www if (url.Contains("//www")) { url = url.Replace("//www", "//"); doRedirect = true; } // redirect if necessary if (doRedirect) { context.Response.Redirect(url); } } is this good: if (!context.Request.HttpMethod.ToString().Equals("GET", StringComparison.OrdinalIgnoreCase)) { // if not a GET method cancel url cosmetics return; }; or should that test be done in Application_BeginRequest? what is better? thnx

    Read the article

  • Determine an elements position in a variable length grid of elements

    - by gaoshan88
    I have a grid of a variable number of elements. Say 5 images per row and a variable number of images. I need to determine which column (for lack of a better word) each image is in... i.e. 1, 2, 3, 4 or 5. In this grid, images 1, 6, 12 and 17 would be in column 1 while 4, 9 and 15 would be in column 4. 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 What I am trying to do is apply a background image to each element based on it's column position. An example of this hard coded and inflexible (and if I'm barking up the wrong tree here by all means tell me how you'd ideally accomplish this as it always bugs me when I see someone ask "How do I build a gold plated, solar powered jet pack to get to the top of this building?" when they really should be asking "Where's the elevator?"): switch (imgnum){ case "1" : case "6" : case "11" : value = "1"; break; case "2" : case "7" : case "12" : value = "2"; break; case "3" : case "8" : case "13" : value = "3"; break; case "4" : case "9" : case "14" : value = "4"; break; case "5" : case "10" : case "15" : value = "5"; break; default : value = ""; } $('.someclass > ul').css('background','url("/img/'+value+'.png") no-repeat');

    Read the article

  • reading newlines with FORMAT statement

    - by peter.murray.rust
    I'm writing a preprocessor and postprocessor for Fortran input and output using FORMAT-like statements (there are reasons not to use a FORTRAN library). I want to treat the new line ("/") character correctly. I don't have a Fortran compiler immediately to hand. Is there a simple algorithm for working out how many newlines are written or consumed (This post just gives reading examples) [Please assume a FORTRAN77-like mentality in the FORTRAN code and correct any FORTRAN syntax on my part] UPDATE: no comments yet so I am reduced to finding a compiler and running it myself. I'll post the answers if I'm not beaten to it. No-one commented I had the format syntax wrong. I've changed it but there may still be errors Assume datafile 1 a b c d etc... (a) does the READ command always consume a newline? does READ(1, '(A)') A READ(1, '(A)') B give A='a' and B='b' (b) what does READ(1,'(A,/)') A READ(1,'(A)') B give for B? (I would assume 'c') (c) what does READ(1, '(/)') READ(1, '(A)') A give for A (is it 'b' or 'c') (d) what does READ(1,'(A,/,A)') A, B READ(1,'(A)') C give for A and B and C(can I assume 'a' and 'b' and 'c') (e) what does READ(1,'(A,/,/,A)') A, B READ(1,'(A)') C give for A and B and C(can I assume 'a' and 'c' and 'd')? Are there any cases in which the '/' is redundant?

    Read the article

  • How to solve the "Growing If Statement" problem?

    - by Achilles
    I've been doing some reading about design patterns and wanted some perspective. Consider the following: Dim objGruntWorker as IGruntWorker if SomeCriteria then objGruntWorker = new GoFor() else if SomeOtherCriteria then objGruntWorker = new Newb() else if SomeCriteriaAndTheKitchenSink then objGruntWorker = new CubeRat() end if objGruntWorker.GetBreakfast() system.threading.thread.sleep(GetMilliSecondsFromHours(4)) objGruntWorker.GetLunch() The above code grows each time a new Criteria arises. I've seen code like this all over the place and in ignorance wrote some of it myself. How should this be solved? Does this kind of anti-pattern have a more "formal" name? Thanks for your help!

    Read the article

  • include and using namespace in C++

    - by cambr
    for using cout, I need to specify both: #include<iostream> and using namespace std; Where is cout defined? in iostream, correct? So, it is that iostream itself is there in namespace std? What is the meaning of both the statements with respect to using cout? I am confused why we need to include them both.

    Read the article

  • Need help with a SELECT statement

    - by Travis
    I express the relationship between records and searchtags that can be attached to records like so: TABLE RECORDS id name TABLE SEARCHTAGS id recordid name I want to be able to SELECT records based on the searchtags that they have. For example, I want to be able to SELECT all records that have searchtags: (1 OR 2 OR 5) AND (6 OR 7) AND (10) Using the above data structure, I am uncertain how to structure the SQL to accomplish this. Any suggestions? Thanks!

    Read the article

  • sp_executesql with 'IN' statement

    - by user300992
    I am trying to use sp_executesql to prevent SQL injection in SQL 2005, I have a simple query like this: SELECT * from table WHERE RegionCode in ('X101', 'B202') However, when I use sp_executesql to execute the following, it doesn't return anything. Set @Cmd = N'SELECT * FROM table WHERE RegionCode in (@P1)' SET @ParamDefinition = N'@P1 varchar(100)'; DECLARE @Code as nvarchar(100); SET @Code = 'X101,B202' EXECUTE sp_executesql @Cmd, @ParamDefinition, @P1 = @Code The is what I have tested: SET @Code = 'X101' <-- This works, it returns a single region SET @Code = 'X101,B202' <--- Returns nothing SET @Code = '''X101'',''B202''' <-- Returns nothing Please help.... what did I do wrong?

    Read the article

  • Error on SQL insert statement

    - by Ashley Stewart
    I exported a recordset from one database into a csv file, and when I try to import it into another using mysql workbench I keep this this error message: Executing SQL script in server ERROR: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 'Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', '' at line 1 INSERT INTO `TRC`.`horse` (`horse_id`, `registered_name`, `stable_name`, `arrival_date`, `last_known_location`, `is_ex_racer`, `birth_year`, `death_date`, `horse_comments`, `sex`, `referral_date`, `horse_height`, `arrival_weight`, `passport_no`, `microchip_no`, `is_on_waiting_list`) VALUES (, 'Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', 'NULL', 'NULL', NULL, NULL, 'NULL', 'NULL', 0) SQL script execution finished: statements: 29 succeeded, 1 failed Fetching back view definitions in final form. Nothing to fetch Any help would be appreciated as their appears to be no errors as far as I can see.

    Read the article

  • Why is this MySQL Join Statement not Working?

    - by Timmy
    Here is my code: $query2 = mysql_query("SELECT * FROM categories WHERE parent = $id JOIN SELECT * FROM posts WHERE main_nav_page = '$idTwo'"); while ($row2 = mysql_fetch_assoc($query2)) { $id = $row2['id']; $name = $row2['name']; $slug = $row2['slug']; $subMenuOrder = $row2['sub_menu_order']; echo "<tr>\n"; echo "<td>&nbsp; -- $name</td>\n"; echo "</tr>\n"; } Is my syntax wrong? EDIT: the error message is: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/studentw/public_html/new_nav.php on line 30

    Read the article

  • Simple question about C# if else statement

    - by ilkdrl
    Iam doing a simple website and when i press button, i should see weight in label.. i see but if text.maxlenght 6, i should see ERROR message in same label but repeat see weight in label. How can i solve this problem? protected void Button1_Click(object sender, EventArgs e) { double sayi1, sayi2, sayi3, hesap, sonuc; sayi1 = Convert.ToDouble(Tb1.Text); sayi2 = Convert.ToDouble(Tb2.Text); sayi3 = Convert.ToDouble(Tb3.Text); if (Tb1.MaxLength > 6 || Tb2.MaxLength > 6) { lbl1.Text = "ERROR."; } else { hesap = (((sayi1 - ((sayi1 - sayi2) / 2)) * ((sayi1 - sayi2) / 2)) / 40); sonuc = (hesap * sayi3) / 100; lbl1.Text = sonuc.ToString() + "kg"; } }

    Read the article

  • Help me refactor this nasty Ruby if/else statement

    - by Suborx
    Hello, so I have this big method in my application for newsletter distribution. Method is for updating rayons and I need to assign a user to rayon. I have relation n:n through table colporteur_in_rayons which has attributes since_date and until_date. I am a junior programmer and I know this code is pretty dummy :) I appreciate every suggestion. def update rayon = Rayon.find(params[:id]) if rayon.update_attributes(params[:rayon]) if params[:user_id] != "" unless rayon.users.empty? unless rayon.users.last.id.eql?(params[:user_id]) rayon.colporteur_in_rayons.last.update_attributes(:until_date => Time.now) Rayon.assign_user(rayon.id,params[:user_id]) flash[:success] = "Rayon #{rayon.name} has been succesuly assigned to #{rayon.actual_user.name}." return redirect_to rayons_path end else Rayon.assign_user(rayon.id,params[:user_id]) flash[:success] = "Rayon #{rayon.name} has been successfully assigned to #{rayon.actual_user.name}." return redirect_to rayons_path end end flash[:success] = "Rayon has been successfully updated." return redirect_to rayons_path else flash[:error] = "Rayon has not been updated." return redirect_to :back end end

    Read the article

  • Regular Expression with Names and Emails

    - by Nina
    I am having a problem with regular expressions at the moment. What I'm trying to do is that for each line through the iteration, it checks for this type of pattern: Lastname, Firstname If it finds the name, then it will take the first letter of the first name, and the first six letters of the lastname and form it as an email. I have the following: $checklast = "[A-z],"; $checkfirst = "[A-z]"; if (ereg($checklast, $parts[1])||ereg($checkfirst, $parts[2])){ $first = preg_replace($checkfirst, $checkfirst{1,1}, $parts[2]); print "<a href='mailto:[email protected];'> $parts[$i] </a>"; } This one obviously broke the code. But I was initially attempting to find only the first letter of the firstname and then after that the first six letters of the lastname followed by the @email.com This didn't work out too well. I'm not sure what to do at this point. Any help is much appreciated.

    Read the article

  • Unreachable code detected in case statement

    - by alex
    I have a code: protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { switch (keyData) { case Keys.Alt|Keys.D1: if (this._condition1) { return true; } else { return base.ProcessCmdKey(ref msg, keyData); } break; case Keys.Control |Keys.U: if (this._condition2) { return true; } else { return base.ProcessCmdKey(ref msg, keyData); } break; default: return base.ProcessCmdKey(ref msg, keyData); } return true; It gives me "unreachable code detected" warning on breaks. Is it good practice not to use break operator here ? I don't want to turn off "unreachable code detected" warning. PS: There are many case in my ProcessCmdKey method.

    Read the article

  • Rails: find_by_sql and PREPARE stmt FROM... i cant make it work

    - by Totty
    I have this query and I have an error: images = Image.find_by_sql('PREPARE stmt FROM \' SELECT * FROM images AS i WHERE i.on_id = 1 AND i.on_type = "profile" ORDER BY i.updated_at LIMIT ?, 6\ '; SET @lower_limit := ((5 DIV 6) * 6); EXECUTE stmt USING @lower_limit;') Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @lower_limit := ((5 DIV 6) * 6); EXECUTE stmt USING @lower_limit' at line 1: PREPARE stmt FROM ' SELECT * FROM images AS i WHERE i.on_id = 1 AND i.on_type = "profile" ORDER BY i.updated_at LIMIT ?, 6'; SET @lower_limit := ((5 DIV 6) * 6); EXECUTE stmt USING @lower_limit; EDIT: after finding the answer to: http://stackoverflow.com/questions/2566620/mysql-i-need-to-get-the-offset-of-a-item-in-a-query i need another help here to port it to rails.

    Read the article

  • Using current database name in T-SQL has Using statement

    - by AmRoSH
    Hello everybody. I have application runs T-SQL statements to update more than one database the problem is i'm using the following t-sql USE [msdb] GO DECLARE @jobId BINARY(16) EXEC msdb.dbo.sp_add_job @job_name=N'test2', @enabled=1, @start_step_id=1, @notify_level_eventlog=0, @notify_level_email=2, @notify_level_netsend=2, @notify_level_page=2, @delete_level=0, @description=N'', @category_name=N'[Uncategorized (Local)]', @owner_login_name=N'sa', @notify_email_operator_name=N'', @notify_netsend_operator_name=N'', @notify_page_operator_name=N'', @job_id = @jobId OUTPUT select @jobId GO EXEC msdb.dbo.sp_add_jobserver @job_name=N'test2', @server_name = N'AMR-PC\SQL2008' GO USE [msdb] GO EXEC msdb.dbo.sp_add_jobstep @job_name=N'test2', @step_name=N'test', @step_id=1, @cmdexec_success_code=0, @on_success_action=1, @on_fail_action=2, @retry_attempts=0, @retry_interval=0, @os_run_priority=0, @subsystem=N'TSQL', @command=N'EXEC sp_MSforeachdb '' EXEC sp_MSforeachtable @command1=''''DBCC DBREINDEX (''''''''*'''''''')'''', @replacechar=''''*''''''', @database_name=N'Client5281', @output_file_name=N'C:\Documents and Settings\Amr\Desktop\Scheduel Reports\report', @flags=2 GO USE [msdb] GO DECLARE @schedule_id int EXEC msdb.dbo.sp_add_jobschedule @job_name=N'test2', @name=N'test', @enabled=1, @freq_type=8, @freq_interval=1, @freq_subday_type=1, @freq_subday_interval=0, @freq_relative_interval=0, @freq_recurrence_factor=1, @active_start_date=20100517, @active_end_date=99991231, @active_start_time=0, @active_end_time=235959, @schedule_id = @schedule_id OUTPUT select @schedule_id GO and i'm using (USE [msdb]) before any block and i want to get database name to replace this @database_name=N'**Client5281**', with the current database name instead of ([msdb]) that i'm using. i hope that i explained what i want well.

    Read the article

  • MySQL Prepared Statements vs Stored Procedures Performance

    - by amardilo
    Hi there, I have an old MySQL 4.1 database with a table that has a few millions rows and an old Java application that connects to this database and returns several thousand rows from this this table on a frequent basis via a simple SQL query (i.e. SELECT * FROM people WHERE first_name = 'Bob'. I think the Java application uses client side prepared statements but was looking at switching this to the server, and in the example mentioned the value for first_name will vary depending on what the user enters). I would like to speed up performance on the select query and was wondering if I should switch to Prepared Statements or Stored Procedures. Is there a general rule of thumb of what is quicker/less resource intensive (or if a combination of both is better)

    Read the article

  • Good practice : compare a value with a boolean?

    - by NLemay
    Most of the time, I prefer to write this : if(isWelcome() == true){} if(isWelcome() == false){} instead of this if(isWelcome()){} if(!isWelcome()){} Because I feel that it is easier to read (but I do understand that it doesn't make sense). I would like to know if there is a common agreement about this practice. What most developer do? And I'm wondering if the compiler is doing the extra comparaison, or if it understand that it is useless.

    Read the article

  • jQuery toggle on a PHP foreach statement

    - by user313835
    The code for the page is the following <?php foreach ($organization->index() as $id=>$content) { ?> <a href="#" id="obtain_branch"><?= $content->name?></a> <div id="directory_brnach"><?= $content->about?></div> <?php } ?> The JavaScript code using jQuery is // Directory inner branches $('#obtain_branch').click(function(){ $('#directory_brnach').toggle('fast'); }); The problem it will only work on the first one given the the ID is not changing, the rest will not change. How can I send an array to the jQuery function to give an individual ID on every iteration? Thanks in advance.

    Read the article

  • PreparedStatement and setTimestamp in oracle jdbc

    - by Roman
    Hi everyone, I am using PreparedStatement with Timestamp in where clause: PreparedStatement s=c.prepareStatement("select utctimestamp from t where utctimestamp>=? and utctimestamp<?"); s.setTimestamp(1, new Timestamp(1273017600000L)); //2010-05-05 00:00 GMT s.setTimestamp(2, new Timestamp(1273104000000L)); //2010-05-06 00:00 GMT The result I get is different, when I have different time zones on the client computer. Is this a bug in Oracle jdbc? or correct behavior? The parameter is Timestamp, and I expected that no time conversions will be done on the way. The database column type is DATE, but I also checked it with TIMESTAMP column type with the same results. Is there a way to achieve correct result? I cannot change default timezone in the the whole application to UTC. Thanks for your help

    Read the article

  • Translate SQL statement into named_scope?

    - by keruilin
    How can I translate this SQL into a named_scope? Also, I want the total comments param to be passed through a lambda. "select users., count() as total_comments from users, comments where (users.id = comments.user_id) and (comments.public_comment = 1) and (comments.aasm_state = 'posted') and (comments.forum_user_id is null) group by users.id having total_comments 25"

    Read the article

  • Prepared statement initialized tiwice and closed once

    - by sonam
    Hi, I want to know that if a PreparedStatement object is initialized twice the way shown in code snippet below and closed only once in finally block, will it fail to close? I am not getting any error in this code but will it be a better idea to use 2 different preparedStatements instead of one. I think it fails to close the preparedStatement at #1. Connection conn = null; PreparedStatement ps = null; try { conn = getConnection(); ps = conn.prepareStatement(QueryUtil.UPDATE_POLICY_DETAILS); // #1 ps.setInt(1, iCancellationPolicyId); ps.executeUpdate(); //some code here ps = conn.prepareStatement(QueryUtil.UPDATE_POLICY_CHARGES); // #2 ps.setInt(1, iCancellationPolicyId); ps.executeUpdate(); //some code here } catch (SQLException sqlExp) { sqlExp.printStackTrace(); LOG.fatal(sqlExp); } finally { conn.close(); ps.close(); }

    Read the article

< Previous Page | 35 36 37 38 39 40 41 42 43 44 45 46  | Next Page >