|
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
|
|
|
|
|
|
Thank you Mr.palikhelsanjeeb.I will go through this link and let you know the result if it is useful. 
|
|
|
|
|
hi
I'm trying to get the weight attached to a computer using RS232 com port.
I can read the weighing, but when I walk out the form , and came again -
My program and computer freezing.
this is my code:
private void Main_Load(object sender, EventArgs e)
{
port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
port.DataReceived += new s system.IO.Ports.SerialDataReceivedEventHandler(Recepcion);
if (port.IsOpen == false)
{
try
{
port.Open();
}
catch (Exception oex)
{
MessageBox.Show(oex.ToString());
}
}
}
private void Actualizar(object s, EventArgs e)
{
lblMSG.Text = ExtractDecimalFromString(port.ReadLine()).ToString();
port.DiscardInBuffer();
lblMSG.Text = ExtractDecimalFromString(port.ReadExisting()).ToString();
port.DiscardInBuffer();
}
private void Recepcion(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
try
{
this.Invoke(new EventHandler(Actualizar));
}
catch { }
}
and when i close the form i do this:
port.DataReceived -= new System.IO.Ports.SerialDataReceivedEventHandler(Recepcion);
GC.Collect();
port.Close();
port.Dispose();
this.Close();
It is not always freezes, sometime yes...sometime no....
I searched the entire network still does not answer and solution.
I'm really despair. I wish to find a solution here
|
|
|
|
|
From where I can see this, I believe you are facing the UI freezing effect (there are various threads that explain what it is in technical aspect). The effect is that, when your application is doing a task that takes some time (if I remember correctly, it was more than 100ms or 1 second) then you need to run that task on a background thread, otherwise your application will freeze and user might think that the application is stuck, because the UI thread doesn't get enough time to update its components or respond to UI interaction; although it is still working properly.
The way you wrote the code, it is a bit tough to consider where you might put a background thread to execute. But the nearest of it to cover the try...catch block in the Recepcion function. There are various ways to solve this problem, and various ways to increase the pain, so I will leave that in your hand to change the code in order to minimize the UI thread to wait for the updating.
Read more here, Asynchronous Programming with Async and Await (C# and Visual Basic)
wpf - C# UI freezing when serial port attempts to connect - Stack Overflow
c# - What causes my UI to freeze when closing a serial port? - Stack Overflow
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
i try this.... still same problem
|
|
|
|
|
1. Check that there are bytes to read (port.BytesToRead > 0 )
2. If you cannot be sure that every message will be terminated by a new line, use port.Read(buffer, 0, count); instead of port.ReadLine() .
|
|
|
|
|
In my experience, "ports" need to be somewhat "stable".
You can't arbitrarily open and close them without expecting a few "connection" fails.
I typically create a single instance for a port in a "longer running" app (including "weighing"), and share that instance; I don't keep opening and closing the port.
Weigh scales also need "wait" times to "center" and respond, etc. At least 100 ms.
I can't picture your scenario as being realistic: repeatedly loading a form to perform a "weighing".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi Dear,
I'm confused about my semester project, Kindly give me some GUI based projects suggestion which can be implemented in C#. I have already done Chatting APP using Client Server Protocol in Java Language and have done many times Management System, In this semester I want to do something new Please Suggested me the projects.
Thanks.
|
|
|
|
|
Go to the CodeProject Articles section, where you will find many suggestions & ideas. But be careful not to copy the code, and submit it as your own work.
|
|
|
|
|
thanks for your advise I will remember your words and appreciate your suggestion !
|
|
|
|
|
Write a web crawler that crawls the internet looking for student project ideas.
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
|
|
|
|