C# :: How To Avoid Duplicate Updates In SQL Query

Jun 13, 2014

I have table called leavetable where in i have the fields eid, lfrom,lto, reason,status an employee will insert these fields in the leave form except status, status will be updated by admin but there is no unique field in the table so when the admin updates the status as cancel for an id emp001 so whereever this id is present in the table its getting updated to cancel even though it is approved previously.. How to avoid this duplication ?

SqlConnection con = new SqlConnection(Connectionstring);
con.Open();
string sql = "update leavetable set status = '"+status+"' where eid = '"+textBox1.Text+"' and noofdays = '"+textBox5.Text+"'";

[Code] .....

View 7 Replies


ADVERTISEMENT

C++ ::  Algorithm To Read Duplicate Array Elements - Return First Duplicate Value Only

Oct 23, 2014

I have an algorithm which uses nested for loops, which looks for duplicate elements in an array. However, as soon as one duplicate element is found... the program will stop looking for more duplicates? My program continues to look for more even though one is found? I know there is a break command but I can't get it to work. Code is below:

output of program: Repeating element found first was: 2, 1

Although I want the outcome to be; Repeating element found first was: 2

#include<stdio.h>
#include<stdlib.h>
#include <iostream>
using namespace std;
void printRepeating(int arr[], int size) {
int i, j;

[Code] .....

View 6 Replies View Related

C# :: MultiThread Blocking Updates During Read

Oct 6, 2014

I have a class holding my data strcuture:

// Holding real time option data - should be thread safe
public class OptionRTHolder {
ConcurrentDictionary<double, Quates> book_calls;
ConcurrentDictionary<double, Quates> book_puts;
ConcurrentDictionary<double, List<Single_qoute>> transaction_calls;
ConcurrentDictionary<double, List<Single_qoute>> transaction_puts;
ConcurrentDictionary<double, int> volume_calls;
ConcurrentDictionary<double, int> volume_puts;
DateTime curr_time;
}

I get a stream of data messages, that come in order, each message carries a time and data. I have many threads in paralell pulling messages and in turn update the data strucutre as follows:

Quates and volume data are just overrun (new value overrun former values), also thier size and meta data is fixed (they don't grow post init).

Via the list I have a problem, I would want to lock only the list I am working on. so other lists can update in paralell, what I had in mind was to warp the list in order to warp the add/get calls to make it thread safety, this I think will achieve this goal and I would like to get some assertion from this forum if you may.

Here come my real problem, there are points in time I want to read/copy this structure, during this time I want to block all updating threads as I want to freeze structure in time, is that achiveable ? Idea that I had is to use something like aquire that will get a function (update/read) and a flag that will cause a lock when the read is on...something like that.

View 3 Replies View Related

C :: How To Avoid Negative Output

Jul 12, 2013

I have a c program that I partially have working. The problem is basically writing a program that allows the user to input the amount of calories they plan to eat a meal and disperse the calories from top to bottom. My program produces the output in the example if I enter 1050 but the issue I noticed if the number of calories is just enough to cover the burgers I get negatives in the other variables.

For example, if I enter a total amount of calories of 1050, I can eat: Output: 2 burgers @ 770 calories (1050 - 770 = 280 calories remain) 1 bag of pretzles @ 170 calories (280 - 170 = 110 calories remain) 1 pear @ 80 calories (110 - 80 = 30 calories remain) 6 tsp. ketchup @ 30 calories If I input 1050 I get the above output but if I input a different integer such as 2000 this is my output 5 burgers @ 1925 calories 0 bag of pretzles @ 0 calories -1 apple @ -80 calories -35 tsp. ketchup @ -175 calories I can't give the full code since this assignment holds a lot of points and was up all night getting it work.

So I'll provide pseudocode

define all 4 variables burger 385, pretzel 170, pear 80, ketchup 5 print out text How many calories can you eat prompt user input
Divide user input into burger How many burgers can bet eaten subtract calories eaten from original user input
Divide calories left into pretzel How many bags can bet eaten subtract burger calories from pretzel calories
Divide calories left after preztel into pear How many pretzels can be eatn subtract pretzels calories from pear calories
Divide calories left over into ketchup how much ketchup can i use show on screen (int total)of burgers @ (int calorie total) calories show on screen (int total)bags of pretzels @ (int calorie total) calories show on screen (int total)pears @ (int calorie total) calories show on screen (int total)teaspoons of ketchup @ (int calorie total) calories

The problem I see is that subtracting the calories from the pear from the left over calories of the pretzel calories leads to a negative. If leftover calories minus 80(pear int) its less then 0 . The calculations from the pear onward to ketchup become incorrect resulting in negative output.

View 6 Replies View Related

C/C++ :: Avoid Using The Goto Function?

Dec 17, 2014

I've been making an RPG in C++ and I've used goto all throughout the program. After receiving an error and Googling how to fix it, I read that you shouldn't use goto. What can I use as a instead of goto, which isn't 'considered bad programming practice'?

View 9 Replies View Related

C++ :: How To Avoid Redundant Code In Classes

Sep 4, 2014

ISSUE: How to avoid redundant code in c++ ?

Problem:Say I have a Base class called Car and it has 3 derived classes say Ford, Honda and Audi.

now the issue is all 3 derived classes have exactly same code but minor difference in calling member functions of their r respective engines( these engines have separate class) . example ford class calls code which is exactly same as other 2 classes but do call something like ford_engine-> start() ford_engine->clean() bla bla bla .

//ly honda calls honda_engine->start() honda_engine->clean();

//ly Audi calls audi_engine->start() audi->clean();

now here the issue is it has redundant code in all 3 places with minute difference. Hoow I can have code at one place most probably in Base class and all derive classes uses same code.

View 1 Replies View Related

C++ :: Way / Pattern To Avoid Copying Data

Apr 19, 2013

I have a class buffer, which holds a std::string as member, and a socket_receive function:

struct buffer {
string data;
buffer() {}
buffer(buffer& b) : data(b.data) {}
};
buffer socket_receive() {
buffer tmp;
tmp.data = "1234";
return tmp;
}

so when I write

buffer b = socket_receive();

there is a copy constructor, and the tmp variable is constructed and destructed, is there anyway to improve the performance?

I tried the new c++11 move(), but seems even worse, I must be doing wrong with move(), but I don't know how.

#include <iostream>
#include <string>
#include <ctime>
using namespace std;
struct buffer {
string data;

[Code] .....

View 4 Replies View Related

C/C++ :: How To Avoid Replacing Element In Array

Oct 6, 2014

I am working on a parking lot scenario project using multidimensional arrays. The parking lot has 8 rows and 10 parking spaces in each row. Altogether there are suppose to be 30 cars parking in the lot and arrive in numerical order. I am suppose to generate a random number to represent the row and another to represent the space in the row.

The problem I have is that a few of the elements are being replaced. The project requires the car to check if the space is taken, if so it is to find another one. Here is what I have...

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define ROW 8
#define COL 10
#define CARS 30
void parkTheCars(int result[ROW][COL]);
void displayArray (int result[ROW][COL]);

[Code] .....

View 1 Replies View Related

C++ :: Can Avoid Class Using Array Operator?

Feb 7, 2014

Imagine these simple class:

Code:
class test {
public:
void write(string a) {
cout << a;
}
};

(these class wasn't tested... it's for these question)... Can avoid the class use the array operator('[]')?

View 7 Replies View Related

Visual C++ :: How To Avoid Memory Fragments

Mar 4, 2015

I am developing a Visual C++ application. There is an object called CMyObject, as follows:

typedef CMap<UINT, UINT, void *, void*> CMyMap;
class CMyObject {
public:
CMyMap *m_pMyMap;
"Some other member variables"
}

Some instances of CMyObject contains a map, some not. Therefore, to save memory, I define a pointer m_pMyMap and create a new CMap object only if the instance contains a map.

When I test my app, with the increase of the CMyObject instance, the number of memory blocks allocated and deallocated is also increasing. There are a lot of fragments during this period. To prevent this, I try to override the new/delete operator for CMyObject and CMyMap. But still find many fragments. So I try to trace into the MFC source codes for CMap. I find CMap is just using an internal buffer to store the hash table(m_pHashTable), as follows:

m_pHashTable = new CAssoc* [nHashSize];

And for each hash entry, it uses:

P = (CPlex *)new BYTE[sizeof(CPlex) + nMax *cbElement];

To allocate the spaces.

I believe these two may be the reason of the memory fragments and want to eliminate them. However, is there a way to override the new/delete operator for codes such as:

new CAssoc* [nHashSize]
and
(CPlex *)new BYTE[sizeof(CPlex) + nMax *cbElement]

So that the spaces will be allocated from my own memory manager instead of from the default heap?

View 1 Replies View Related

C++ :: How To Avoid Using Backspace Character With Push Back

Mar 28, 2014

How to avoid using Backspace character with push_back? I'm making a software as an ATM, so when the user try to enter the password the user only sees *******, but when trying to delete it doesn't delete a character. It just adds a new one. Here's my code:

string password2 = "";
cout << "PASSWORD: ";
ch = _getch();
while(ch != 13) //character 13 is enter {
password2.push_back(ch);
cout << '*';
ch = _getch();
}

And also, I try to use pop_back(); but it doesn't work either.

View 6 Replies View Related

C++ :: How To Avoid If Fstream Opens A Directory (infinite Loop)

Jun 10, 2013

If the filename below is a directory, then the following loop goes to infinite.

std::ifstream in;
in.open(filename, std::ifstream::in);
if(in.fail()) return;

[Code].....

View 1 Replies View Related

C# :: Populating GridView With SQL Query

Apr 3, 2014

I have two tables

Orders
ID, CreatedDate,CustomerID
1, 03/04/2014, test

OrderDetails
ID,ProductId, ProductName,Quantity,Price,Total
1, 5, Toy, 5, 1.99, 9.95

I have a gridview, im using its 'datasource dropdownlist' to populate it, i have the SQL statement

SELECT Orders.ID, OrderDetails.ProductId, OrderDetails.ProductName, OrderDetails.Quantity, OrderDetails.Price, OrderDetails.Total FROM (OrderDetails INNER JOIN Orders ON OrderDetails.ID = Orders.ID) WHERE (Orders.CustomerId = ?)

where the '?' is parameters source = QueryString, and QueryStringField= email

i have a session that is the customerEmailId, so

string CustomerEmailID = (string)Session["email"];
Response.Redirect("MyAccount.aspx?email=" + CustomerEmailID);//i have tested it and customerEmailid is test
however nothing loads in the GridView

View 1 Replies View Related

C# :: Run SQL Query For Each Item In Listbox?

Aug 2, 2014

I have a C# WPF program that takes a SQL query and populates a column from an Oracle database into a listbox on the form. I would like to be able to compare all items populated in the listbox, and run a SQL query for each item, populating those values into a different listbox.

So far, I have this code:

string sql2 = "select unique apps.fnd_application_all_view.application_name, fnd_responsibility_vl.responsibility_name, fnd_form_functions_tl.user_function_name, fnd_form_functions.function_name, fnd_form_functions_tl.description, fnd_form_functions.type FROM fnd_compiled_menu_functions, fnd_form_functions, fnd_form_functions_tl, fnd_responsibility, fnd responsibility_vl, apps.fnd_application_all_view WHERE

[code]....

I would like to be able to basically take the "Responsibility_Name" value from the first listbox (lstResponsibilities), which is already populated, and use those values to in the "sql2" query to find the "Function_Name" and populate "Function_Name" in the second listbox (lstFunctions).

View 5 Replies View Related

C++ :: Generate List Of Tokens For A Query

Jun 9, 2013

I'm trying to solve the following problem:

Given a query, find all possible tokens, i.e. query-splits

Example:
query = New York Hotel
tokens = {New, York, Hotel, New York, New Hotel, ...., New Hotel York, Hotel New York, ...}

Given a query with word count n, the total number of tokens is:
n + n*(n-1) + n*(n-1)*(n-2) + ... + n! (any explicit formula available for this sum?)

Now, I have came across various code snippets to generate permutations for a string, but never for a sentence.

View 13 Replies View Related

C# :: Combine Query To Show All Data

Sep 22, 2014

So I've been working on this for awhile and FINALLY got it to work. This is my code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

[Code] ....

As you can see I will have the Name and total right next to eachother.. Problem is I dont want to make a million MySQLCommands for each ID.. Is there a Way I can list all data in each label?

For instance the Select from Text will show all the text from each different ID
and the Select from STOCK-USED as total will show all the total for each ID

Instead of having to list them individually.

Even if I leave it to this

"Select text FROM `parts`";

It selects the 2nd ID in my database and displays its text.. Forgets about the first one completely ...

View 2 Replies View Related

C# :: How To Pass SQL Parametrized Query To WCF Web Service

Nov 16, 2014

I have WCF web service which contains methods for communicating with database (ms sql). For a long time I was using pure sql statements, that aren't secure. It is time to move to parameterized queries. I'm using code-engine.com source code for query builder. Example of it is here: SelectQueryBuilder: Building complex and flexible SQL queries/commands from C# . Which works OK and I have no problems when is used inside of web service.

The problem: I also have asp.net web site which uses this webservice and the main problem is, how to build queries on client side and sent them to web service? I can build query on client side and send dbCommand.commandtext but I then I don't know how to send parameters list to webservice, because it isn't serialized.

This would be used as "universal" method for sql statements. I have others method like getUser(),getUsers(),getPages() but I really need this kind of methods to pass query to it.

View 1 Replies View Related

C# :: Update Multiple Tables In One Query?

Jul 23, 2014

i'm trying to update multiple table values with same column using one query.

Here's what i've tried so far:

mySql.CommandText = "Update tbl_employees,tbl_emp_additional_info,tbl_allocated_deductions,tbl_benefits,
tbl_cashadvances,tbl_deduction_history,"+
"tbl_dtr,tbl_empabsences,tbl_empstatus,tbl_otherdeductions
,tbl_ots,tbl_payroll_history,tbl_rdcomments,tbl_reversed_deductions,tbl_reversed_deduction_paid "+
"set tbl_employees.emp_id=@newemp_id,tbl_emp_additional_info.emp_id=@newemp_id,tbl_allocated_deductions.

[code]...

I've also tried removing all the other "and" operators but still no luck.It doesn't throw in exception yet it doesn't update my tables column values.

View 14 Replies View Related

C# :: Including A String In SQL Query For Excel Spreadsheet

Jan 15, 2015

I am displaying data from an Excel Spreadsheet through an ASP.net web form using C#. I would like to run an SQL query on the data, but am having trouble figuring out how to use a string in my query.

Here is the code I am running in my .aspx.cs file. I am also using a .aspx to display the data in a GridView.

public partial class ExcelAdapter : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("ExcelCSTest.xls") + ";" + "Extended Properties="Excel 8.0;HDR=Yes;IMEX=1"";

[Code] ....

Ideally, I would like to add a WHERE clause to my string (string sSQL = "SELECT * FROM [Sheet1$A1:D14]"/> in order to query the current month and display the row of said month from the Excel Spreadsheet.

I have attempted to use a DataAdapter to insert the string into the query, but could not figure out how to conform my code to work with it.

View 1 Replies View Related

C# :: Multiple Update Query After Filter In Datagridview

Oct 11, 2014

I'm new to c# and i'm using vs 2013 and access database..my i need to do multiple update records after I filtered the records in datagridview

In my database table I have these fields ID(PK/autonumber), EID,Date,Day,Daystatus..

In my form I have a button and it's fucntion is filter by date using bidingsource.fiter and this was the result

EID------Date-----------Day---Daystatus
10175--10/11/2014---sat--------regular
10176--10/11/2014---sat--------regular
10177--10/11/2014---sat--------regular
10178--10/11/2014---sat--------regular

what I want to happen is when I click another button called "Apply to all" I want to Update all the daystatus to "Legal Holiday" of the filtered records..I know how to update one by one using simple update..but I need to do the multiple update..

I tried to make a code but it was updating all the records not the filtered only here's my code:

try {
OleDbCommand command = new OleDbCommand();
connection.Open();
command.Connection = connection;
string query = "SELECT EID From EmployeeTable";
command.CommandText = query;
String a = "Legal Holiday";

[Code] ......

View 1 Replies View Related

C Sharp :: Using List Elements As Variable In Query

Aug 27, 2014

I am trying to query an Informix database using a List<T> collection's elements as variables. I can build the list and connect to the database, but I am unsure how to iterate through the list and query the database for each item in the collection.

My list is of type string, and contains Order Numbers. I want to query item information for each order number in the list.

View 1 Replies View Related

C++ :: Bool Algebra - Designing Database Query

May 15, 2012

I am designing a database query and need simplification to the algebra:

Code:
((x > u) && (x < y)) || ((z > u) && (z < y)) || ((u > z) && (y < x))

And these are always true:

Code:
z > x
u > y

It's a range overlap algorithm.

View 4 Replies View Related

C++ :: How To Duplicate String Array

Sep 8, 2014

I'm trying to duplicate a string array. I created a function called duplicate but, when i run it, it gives me an error... what is wrong with it?

#include <iostream>
#include <string>
#include <fstream>
#include <array>
#define ARRAY_SIZE(array) (sizeof((array))/sizeof((array[0])))

[Code] .....

View 3 Replies View Related

C/C++ :: Removing Duplicate Values From Map?

Mar 1, 2015

im working on a homework assignment t that should print all pairs of integers that sum to val. I have so far finished except It prints duplicate values (ie (3,1) and(1,3) for values that add to 4) . how can i remove these duplicate pairs of values?

#include <iostream>
#include <map>
#include <vector>
using namespace std;
void printPairs( vector<int> numbers, int val){
int i;

[code]....

View 2 Replies View Related

Visual C++ :: LINQ Query To Select Distinct Value From Datatable

Oct 29, 2013

I entered to Visual C++ 2010. Now my intention is to prepare a LINQ Query to select a distinct value from a datatable...

In C# My Query
============
var ProjLnkQry = (from P in MyClass1.ProjTbl.AsEnumerable() select P["proj_name"]).Distinct().ToList();

The above query I try to convert it into VIsual C++

auto DistDepQry=(from v1 in MyGlobalData::ProjectTbl::AsEnumaerable() select v1["depart_name"])->Distinct()->ToList();

But not succeeded.... I found the error like : "from" undeclared Identifier.....

View 2 Replies View Related

C :: Removing Duplicate Elements From Array

Nov 4, 2013

While removing duplicate elements from an array, if more than 4 array elements are same then removal does not work. however my logic seems to be alright. i reckon there is a problem with the conditions and assignments in the three for loops that i have used. the program is as follows:

Code:
/*c program to remove duplicate elements in an array*/
#include<stdio.h>
int main(void)
{
int array[30],i,j,k,n;
printf("

[Code] ....

Take for instance if the input elements are 1,1,1,1,1,2,2,3,5 then after removal of duplicacy the array is 1,1,2,3,5.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved