|
Why is my code not returning numbers such as 20000, 30000, 40000 etc. it just returns twenty and ignores the thousand.
Console.WriteLine(DateTime.Now);
Console.WriteLine("Welcome To Ayoola's Number Converter");
string[] units = new string[] { " ","ONE ", "TWO ", "THREE ", "FOUR ", "FIVE ", "SIX ", "SEVEN ", "EIGHT ", "NINE ", "TEN ", "ELEVEN ", "TWELVE ", "THIRTEEN ", "FOURTEEN ", "FIFTEEN ", "SIXTEEN ", "SEVENTEEN ", "EIGHTEEN ", "NINETEEN " };
string[] tens = new string[] { " ","TEN ", "TWENTY ", "THIRTY ", "FOURTY ", "FIFTY ", "SIXTY ", "SEVENTY ", "EIGHTY ", "NINETY " };
string[] big = new string[] { "hundred ", "Thousand ", "million", "billion" };
long i, num;
string result = "";
Console.WriteLine("Enter number here : ");
String input = Console.ReadLine();
num = long.Parse(input);
if (num < 1000000000000 && num > 99999999999)
{
i = num / 100000000000;
result = units[i] + "HUNDRED " + "AND ";
num = num % 100000000000;
}
if (num > 19999999999 && num < 100000000000)
{
i = num / 10000000000;
result += tens[i];
num = num % 10000000000;
}
if (num > 999999999 && num < 20000000000)
{
i = num / 1000000000;
result += units[i] + "BILLION ";
num = num % 1000000000;
}
if (num > 99999999 && num < 1000000000)
{
i = num / 100000000;
result += units[i] + "HUNDRED " + "AND ";
num = num % 100000000;
}
if (num >= 20000000 && num < 100000000)
{
i = num / 10000000;
result += tens[i] ;
num = num % 10000000;}
if (num >= 1000000 && num < 20000000)
{
i = num / 1000000;
result += units[i] + "MILLION ";
num = num % 1000000;
}
if (num > 100000 && num < 1000000)
{
i = num / 100000;
result += units[i] + "HUNDRED " + "AND " ;
num = num % 100000;
}
if (num > 19999 && num < 100000)
{
i = num / 10000;
result += tens[i];
num = num % 10000;
}
if (num > 999 && num <= 19999)
{
i = num / 1000;
result += units[i] + "THOUSAND ";
num = num % 1000;
}
if (num > 99 && num < 1000)
{
i = num / 100;
result += units[i] + "HUNDRED " + "AND ";
num = num % 100;
}
if (num > 19 && num < 100)
{
i = num / 10;
result = result + tens[i];
num = num % 10;
}
if (num < 20 && num >= 0)
{ result += units[num]; }
if (num == 0)
result += "";
Console.WriteLine("The number in words: " + result);
string sample = "1234";
string s = "1234";
for (int y = s.Length ; y > 0; y-= 3 )
{
if(y-3 > 0)
{
Console.WriteLine(s.Substring(y - 3, 3));
}
}
Console.WriteLine(sample.Substring(1,3));
Console.ReadLine();
|
|
|
|
|
Look at the following code:
if (num > 19999 && num < 100000)
{
i = num / 10000;
result += tens[i];
num = num % 10000;
}
If you start with 20,000, then i will become 2, and num will become zero. But in the code that follows you have no way of determining that the 2 refers to thousands. You need to rethink your calculations.
|
|
|
|
|
Because the code
if (num > 19999 && num < 100000)
{
i = num / 10000;
result += tens[i];
num = num % 10000;
}
is missing the THOUSAND. In fact you can't handle hundred and tels of thousand separately from units of thousand.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. It allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
To see how others are doing for the same problem:
Coding challenge: convert an integer to a sentence.[^]
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
modified 23-Jan-17 18:05pm.
|
|
|
|
|
Thanks for pointing out the Debugging article. I did not see it before today. And this old dog learned a new trick. Hopefully I will remember it when I need it.
|
|
|
|
|
 many of the if conditions needs to be worked upon but for instance like 20_000 or 1_00_000, these issues are solved for your reference . But for the cases like 200_200_000, you still need to work around.please see the attached code which rectifies your problem for given cases 20_000 or likewise.
Hope this proves to be helpful
Console.WriteLine(DateTime.Now);
Console.WriteLine("Welcome To Ayoola's Number Converter");
string[] units = new string[] { " ", "ONE ", "TWO ", "THREE ", "FOUR ", "FIVE ", "SIX ", "SEVEN ", "EIGHT ", "NINE ", "TEN ", "ELEVEN ", "TWELVE ", "THIRTEEN ", "FOURTEEN ", "FIFTEEN ", "SIXTEEN ", "SEVENTEEN ", "EIGHTEEN ", "NINETEEN " };
string[] tens = new string[] { " ", "TEN ", "TWENTY ", "THIRTY ", "FOURTY ", "FIFTY ", "SIXTY ", "SEVENTY ", "EIGHTY ", "NINETY " };
string[] big = new string[] { "hundred ", "Thousand ", "million", "billion" };
long i, num;
while (true)
{
string result = "";
Console.WriteLine("Enter number here : ");
String input = Console.ReadLine();
num = long.Parse(input);
if (num < 1000000000000 && num > 99999999999)
{
i = num / 100000000000;
result = units[i] + "HUNDRED " + "AND ";
num = num % 100000000000;
}
if (num > 19999999999 && num < 100000000000)
{
i = num / 10000000000;
result += tens[i];
num = num % 10000000000;
}
if (num > 999999999 && num < 20000000000)
{
i = num / 1000000000;
result += units[i] + "BILLION ";
num = num % 1000000000;
}
if (num > 99999999 && num < 1000000000)
{
i = num / 100000000;
num = num % 100000000;
if (num != 0) { result += units[i] + "HUNDRED " + "AND "; }
else { result += units[i] + "HUNDRED " + "MILLION "; }
}
if (num >= 20000000 && num < 100000000)
{
i = num / 10000000;
result += tens[i];
num = num % 10000000;
}
if (num >= 1000000 && num < 20000000)
{
i = num / 1000000;
result += units[i] + "MILLION ";
num = num % 1000000;
}
if (num >= 100000 && num < 1000000)
{
i = num / 100000;
num = num % 100000;
if(num != 0) { result += units[i] + "HUNDRED " + "AND "; }
else { result += units[i] + "HUNDRED " + "THOUSAND "; }
}
if (num > 19999 && num < 100000)
{
i = num / 10000;
result += tens[i];
num = num % 10000;
if(num == 0)
{
result += "THOUSAND";
}
}
if (num > 999 && num <= 19999)
{
i = num / 1000;
result += units[i] + "THOUSAND ";
num = num % 1000;
}
if (num > 99 && num < 1000)
{
i = num / 100;
result += units[i] + "HUNDRED " + "AND ";
num = num % 100;
}
if (num > 19 && num < 100)
{
i = num / 10;
result = result + tens[i];
num = num % 10;
}
if (num < 20 && num >= 0)
{ result += units[num]; }
if (num == 0)
result += "";
Console.WriteLine("The number in words: " + result);
}
modified 26-Jan-17 4:03am.
|
|
|
|
|
How to save values in SQL in two different columns in a table without crashing of the values in a network.
Ex: There are 20 users in my network.All wants to update one particular row at a time.
Here the crashing has been taken place.That means suppose I have taken one table in that many columns there.The user wants to update two columns a,b with their values at a time. when we click on update sometimes it swaps the data.
a=10,
b=20 i want to update
but it updated like this a=20,b=10
sometimes it has been taken null value also.
Why does it happen?
If you explain how to solve this problem.It would be appreciated.
I have written this code in c# to save.But while users saving at a time one row.The swapping of column values saving taken place.
sqlstr = "Insert into invINVOICEDETAILS (comment_NAME30, PRODUCT_NO, PRODUCT_NAME, QTY, UOM, PRICE, ITEM1_NO, DISCOUNT_PC, AMOUNT, SC_NO, GL_CODE, PROJ_NO, Gp_NO, WH_NO, Sales_exempt,FACTOR," +
"Category, IMPORTED_FROM_NO, IMPORTED_FROM, GST_Amt, DISCOUNT_PC_2,Ref_No, GL_DESC, PRODUCT_NAME_LONG, CREATED_BY," +
"DATE_CREATED, Deleted, INV_NO,Transfer, TICK, ID, AC_NO, AC_NAME, ITEM10, invNo_user, AVERAGE_COST, LP_COST, STD_COST,QTY_UNFILLED,DATETIME,Batch_No," +
"Expiry_Date,PRINT_ITEM,QTY_BILLED,ITEM6_NO,ITEM7_NO,ITEM8_NO,IMPORT_KEY) values (@comment_NAME30,@PRODUCT_NO,@PRODUCT_NAME,@QTY,@UOM,@PRICE," +
"@ITEM1_NO,@DISCOUNT_PC,@AMOUNT,@SC_NO,@GL_CODE,@PROJ_NO,@Gp_NO," +
"@WH_NO,@Sales_exempt,@FACTOR,@Category,@IMPORTED_FROM_NO," +
"@IMPORTED_FROM,@GST_Amt,@DISCOUNT_PC_2,@Ref_No,@GL_DESC," +
"@PRODUCT_NAME_LONG, @CREATED_BY, @DATE_CREATED, @Deleted, @INV_NO," +
"@Transfer,@TICK,@ID,@AC_NO,@AC_NAME,@ITEM10,@invNo_user,@AVERAGE_COST," +
"@LP_COST,@STD_COST,@QTY_UNFILLED,@DATETIME,@Batch_No,@Expiry_Date," +
"@PRINT_ITEM, @QTY_BILLED,@ITEM6_NO,@ITEM7_NO,@ITEM8_NO,@IMPORT_KEY)";
}
else
{
sdata += "PRODUCT_NAME_LONG=N'" + cfs.singlequotconver(strdesc) + "', UPDATED_BY ='" + uid.ToString() + "',DATE_UPDATED='" + cfs.sqldateconverion() + "',Deleted='False',invNo_user='" + ddl_Inv.Text + uid.ToString() + "',CREATED_BY='" + uid + "' ," +
"Transfer='U',TICK='C',AC_NO='" + cfs.singlequotconver(txt_Custcode.Text) + "',AC_NAME=N'" + cfs.singlequotconver(txt_Cus_Name.Text) + "',QTY_BILLED=" + Prodqty + ",ITEM10='" + cfs.singlequotconver(LineNo) + "',AVERAGE_COST=(select distinct AVERAGE_COST from PRODUCT where PRODUCT_NO='" + strpcode + "'),LP_COST=(select distinct LP_COST from PRODUCT where PRODUCT_NO='" + strpcode + "'),STD_COST=(select distinct STD_COST from PRODUCT where PRODUCT_NO='" + strpcode + "'),QTY_UNFILLED='" + strqtyfilled + "',DATETIME='" + cfs.sqldateconverion(txt_trans_Date.Value) + "'";
try
{
if (row.Cells["no"].Value.ToString() == "1")
{
sdata += ",PRINT_ITEM='GD',Batch_No='" + row.Cells["BATCH_CODE"].Value.ToString() + "',Expiry_Date='" + row.Cells["EXPIRY_DATE"].Value.ToString() + "'";
}
}
catch (Exception Ex) { }
if (ZeroQtySave)
{
try
{
sdata += ",ITEM6_NO=" + cfs.IsNumber(row.Cells["Qty"].Value.ToString()) + ",ITEM7_NO='" + pri + "',ITEM8_NO='" + cfs.IsNumber(row.Cells["NetAmount"].Value.ToString()) + "' ";
}
catch (Exception Ex)
{
}
}
sqlstr = "update invINVOICEDETAILS set comment_NAME30=@comment_NAME30," +
"PRODUCT_NO=@PRODUCT_NO,PRODUCT_NAME=@PRODUCT_NAME,QTY=@QTY,UOM=@UOM,PRICE=@PRICE," +
"ITEM1_NO=@ITEM1_NO,DISCOUNT_PC=@DISCOUNT_PC,AMOUNT=@AMOUNT,SC_NO=@SC_NO," +
"GL_CODE=@GL_CODE,PROJ_NO=@PROJ_NO,Gp_NO=@Gp_NO,WH_NO=@WH_NO,Sales_exempt=@Sales_exempt,FACTOR=@FACTOR,GST_Amt=@GST_Amt,DISCOUNT_PC_2=@DISCOUNT_PC_2," +
"PRODUCT_NAME_LONG=@PRODUCT_NAME_LONG,Category=@Category,IMPORTED_FROM_NO=@IMPORTED_FROM_NO,UPDATED_BY =@UPDATED_BY,DATE_UPDATED=@DATE_UPDATED," +
"Deleted=@Deleted,CREATED_BY=@CREATED_BY ,Transfer=@Transfer,TICK=@TICK,AC_NO=@AC_NO," +
"AC_NAME=@AC_NAME,QTY_BILLED=@QTY_BILLED,ITEM10=@ITEM10,invNo_user=@invNo_user,IMPORTED_FROM=@IMPORTED_FROM,AVERAGE_COST=@AVERAGE_COST,LP_COST=@LP_COST,STD_COST=@STD_COST," +
"QTY_UNFILLED=@QTY_UNFILLED,DATETIME=@DATETIME,Batch_No=@Batch_No,Expiry_Date=@Expiry_Date,PRINT_ITEM=@PRINT_ITEM," +
"ITEM6_NO=@ITEM6_NO,ITEM7_NO=@ITEM7_NO,ITEM8_NO=@ITEM8_NO,IMPORT_KEY=@IMPORT_KEY where LINE = @LINE";
}
cmdTemp.CommandText = sqlstr;
try
{
cmdTemp.Parameters.AddWithValue("@comment_NAME30", ((object)row.Cells[0].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("PRODUCT_NO", ((object)row.Cells[1].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@PRODUCT_NAME", ((object)row.Cells[2].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@QTY", ((object)row.Cells[3].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@UOM", ((object)row.Cells[4].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@PRICE", ((object)row.Cells[5].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@ITEM1_NO", ((object)row.Cells[6].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@DISCOUNT_PC", ((object)row.Cells[7].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@AMOUNT", ((object)row.Cells[8].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@SC_NO", ((object)row.Cells[10].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@GL_CODE", ((object)row.Cells[11].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@PROJ_NO", ((object)row.Cells[12].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@Gp_NO", ((object)row.Cells[13].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@WH_NO", ((object)row.Cells[14].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@Sales_exempt", ((object)row.Cells[15].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@FACTOR", ((object)row.Cells[16].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@Category", ((object)row.Cells[18].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@IMPORTED_FROM_NO", ((object)row.Cells[19].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@IMPORTED_FROM", ((object)row.Cells[20].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@GST_Amt", ((object)row.Cells[23].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@DISCOUNT_PC_2", ((object)row.Cells[24].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@Ref_No", ((object)row.Cells[25].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@GL_DESC", ((object)row.Cells[27].Value) ?? DBNull.Value);
cmdTemp.Parameters.AddWithValue("@PRODUCT_NAME_LONG", cfs.singlequotconver(strdesc));
cmdTemp.Parameters.AddWithValue("@CREATED_BY", uid.ToString());
cmdTemp.Parameters.AddWithValue("@DATE_CREATED", cfs.sqldateconverion());
cmdTemp.Parameters.AddWithValue("@Deleted", "False");
cmdTemp.Parameters.AddWithValue("@INV_NO", ddl_Inv.Text);
cmdTemp.Parameters.AddWithValue("@Transfer", "U");
cmdTemp.Parameters.AddWithValue("@TICK", "C");
cmdTemp.Parameters.AddWithValue("@ID", strInvId);
cmdTemp.Parameters.AddWithValue("@AC_NO", cfs.singlequotconver(txt_Custcode.Text));
cmdTemp.Parameters.AddWithValue("@AC_NAME", cfs.singlequotconver(txt_Cus_Name.Text));
cmdTemp.Parameters.AddWithValue("@ITEM10", cfs.singlequotconver(LineNo));
cmdTemp.Parameters.AddWithValue("@invNo_user", ddl_Inv.Text + uid.ToString());
cmdTemp.Parameters.AddWithValue("@AVERAGE_COST", cfs.get_data("select distinct AVERAGE_COST from PRODUCT where PRODUCT_NO='" + strpcode + "'"));
cmdTemp.Parameters.AddWithValue("@LP_COST", cfs.get_data("select distinct LP_COST from PRODUCT where PRODUCT_NO='" + strpcode + "'"));
cmdTemp.Parameters.AddWithValue("@STD_COST", cfs.get_data("select distinct STD_COST from PRODUCT where PRODUCT_NO='" + strpcode + "'"));
cmdTemp.Parameters.AddWithValue("@QTY_UNFILLED", strqtyfilled);
cmdTemp.Parameters.AddWithValue("@DATETIME", cfs.sqldateconverion(txt_trans_Date.Value));
cmdTemp.Parameters.AddWithValue("@Batch_No", batchno);
cmdTemp.Parameters.AddWithValue("@Expiry_Date", Expirydate);
cmdTemp.Parameters.AddWithValue("@PRINT_ITEM", printitem);
cmdTemp.Parameters.AddWithValue("@QTY_BILLED", Prodqty);
cmdTemp.Parameters.AddWithValue("@ITEM6_NO", Prodqty);
cmdTemp.Parameters.AddWithValue("@ITEM7_NO", pri);
cmdTemp.Parameters.AddWithValue("@ITEM8_NO", net);
cmdTemp.Parameters.AddWithValue("@IMPORT_KEY", ((object)row.Cells[21].Value) ?? DBNull.Value);
if (isexisted == true)
{
cmdTemp.Parameters.AddWithValue("@LINE", strid);
cmdTemp.Parameters.AddWithValue("@UPDATED_BY", uid.ToString());
cmdTemp.Parameters.AddWithValue("@DATE_UPDATED", cfs.sqldateconverion());
}
}
catch (Exception EX) { }
Im
Tarun Kumar
|
|
|
|
|
Does the code work properly when there is no concurrent request in the network? In database systems, especially when there are multiple users requesting or modifying the data there are going to be problems. This has been haunting database systems since the days of Codd. If your data is being stored accurately (or as expected) when only one user access it, then the problem is with concurrency. Concurrency control - Wikipedia.
Please also share the results of my suggestion, so that we may look into this again. Also, did you try stored procedures?
Database systems although try their best to ensure that synchrony is maintained but sometimes that is not enough. My first solution (although a very naive one) would be, to lock the thread and perform one action and then perform the action of other user.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thank you Mr.Afzaal.I have also even tried stored procedures and Parameterised queries.But when the huge amount of data has been taken place then this problem appear at my side.So can u please explain the concept of concurrency and locking the thread.I have already used threading in my project.At customer side when multiple users are creating transactions at the single time, crashing occurred.
|
|
|
|
|
That happens.
Well, for further explanations kindly see the links I provided. They have a good resource start up that you can use for your application.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
|
Thank you Mr.Simon_Whale.Can u please explain it briefly.What is the use of it?
|
|
|
|
|
If you read the documentation link, it tells you what its scope is.
This space for rent
|
|
|
|
|
it requires more reading from yourself but have a read of this All About TransactionScope[^]
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Thank you Simon for your document shared.I will go through it and let you know the result.
|
|
|
|
|
It looks like you're part-way through rewriting your code to avoid SQL Injection.
As a result, you can remove all of the code that's building up the sdata string, since it's no longer used.
The lines which call cfs.get_data are still vulnerable, and need to be rewritten to use parameters.
You need to remove the calls to cfs.singlequotconver . Based on the name, it's trying to avoid SQL Injection by "escaping" quote characters. Since you're now using parameters, you don't need to do that.
You should also remove the call to cfs.sqldateconverion , which is probably converting the date to a string. Dates should be passed and stored as dates.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you Mr.Ricard.These may be one of the reasons of data crashing.I will try to do modifications at my side and let you know the concerns about this.
|
|
|
|
|
Here Passing a query as a parameter to get_data method.How can we use parameters here?
public string get_data(string sqlstr)
{
string strTemp = "";
try
{
double sum = 0;
if (cn.State != ConnectionState.Open) cn.Open();
TRcmd2.Connection = cn;
TRcmd2.CommandText = sqlstr;
TRdr = TRcmd2.ExecuteReader();
if (TRdr.Read())
strTemp = TRdr.GetValue(0).ToString();
TRdr.Close();
}
catch
{
try
{
if (!TRdr.IsClosed == true) TRdr.Close();
}
catch (Exception EX) { }
}
return (strTemp);
}
|
|
|
|
|
For a start, don't store connection and command objects in fields. Instead, create them when you need them, and wrap them in a using block to ensure that they're always disposed of properly.
You don't need to call ExecuteReader to get the value of the first column of the first row; use ExecuteScalar[^] instead.
And you need to add a params parameter[^] to your method to pass parameters:
private static void PrepareCommand(SqlCommand command, string commandText, object[] parameters)
{
if (parameters != null && parameters.Length != 0)
{
string[] parameterNames = new string[parameters.Length];
for (int index = 0; index < parameters.Length; index++)
{
string name = "@p" + index;
parameterNames[index] = name;
command.Parameters.AddWithValue(name, parameters[index]);
}
commandText = string.Format(commandText, parameterNames);
}
command.CommandText = commandText;
}
public string get_data(string commandText, params object[] parameters)
{
using (var connection = new SqlConnection(ConnectionString))
using (var command = new SqlCommand(string.Empty, connection))
{
PrepareCommand(command, commandText, parameters);
connection.Open();
object result = command.ExecuteScalar();
return Convert.ToString(result);
}
}
You can then pass parameters to the command using the auto-generated names:
cfs.get_data("select top 1 AVERAGE_COST from PRODUCT where PRODUCT_NO = @p0", strpcode)
or by position:
cfs.get_data("select top 1 AVERAGE_COST from PRODUCT where PRODUCT_NO = {0}", strpcode)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I tried all the points as you mentioned here.But still, invoice number clash happens when the multiple users save at a time.Here the invoice number is unique.But in details part we can save multiple products for a particular invoice.But here clash happens when multiple users enter data at once.
for example
users-->invoice no Products
Raj 1 J,K
Tarun 2 O,M
But at the time of saving it swapped like this
users-->invoice no Products
Raj 1 J,K,M-------->Clashing taken place
Tarun 2 O
Please give me suggestions to solve this.
|
|
|
|
|
1) You're probably updating way more fields than the "business rule" requires; possibly fouling up foreign keys in the process.
2) Maybe a "Delete and insert" makes more sense than an "update" here.
3) It seems you're arbitrarily overwriting everything. You will probably have better success if you incorporate "versioning"; which will also make your "WHERE" clauses more intelligent instead of blindly accessing by line# only. That, and a transaction.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thank you Mr.Gerry.These may be one of the reasons of data crashing.Can u please explain the point 3 briefly and give me ways to write short code for that.
|
|
|
|
|
|
I tried all the points as you mentioned here.But still, invoice number clash happens when the multiple users save at a time.Here the invoice number is unique.But in details part we can save multiple products for a particular invoice.But here clash happens when multiple users enter data at once.
for example
users-->invoice no Products
Raj 1 J,K
Tarun 2 O,M
But at the time of saving it swapped like this
users-->invoice no Products
Raj 1 J,K,M-------->Clashing taken place
Tarun 2 O
Please give me suggestions to solve this.
|
|
|
|
|
Where's the version number?
I don't see any evidence of you "trying all the points".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
|