|
It probably won't be a problem for this query, but in general this method would interpret the concatenated column as XML. This could lead to errors, or to characters being "entitized".
The fix is fairly simple:
SELECT Id, Conditions=
STUFF((SELECT ',' + CONVERT(varchar(10), Condition)
FROM myTable b
WHERE b.Id = a.Id
FOR XML PATH(''), TYPE).value('.', 'varchar(max)'), 1, 1, '')
FROM myTable a
GROUP BY Id
Concatenating Row Values in Transact-SQL[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
from what I understand, when using session ended event, the action will be done if the computer shuts down or if the user logs off.
I have this event, but the action only occurs when the computer shuts down, but when the user logs off, nothing happens.
Here is the code I'm using:
SystemEvents.UserPreferenceChanging += new UserPreferenceChangingEventHandler(SessionEnded);
static void SessionEnded(object sender, UserPreferenceChangingEventArgs e)
{
}
Can some one please tell me how to make my app do something, when the user logs off?
Thanks.
|
|
|
|
|
Member 10850253 wrote: I have this event You have the "UserPreferenceChanging" event.
Try SessionEnding[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I tried:
InitializeComponent();
SystemEvents.SessionEnding += (s, e) =>
{
switch(e.Reason){
case SessionEndReasons.Logoff:
ComPort.Close();
ComPort.Write(new byte[] { 48 }, 0, 1);
break;
case SessionEndReasons.SystemShutdown:
ComPort.Close();
ComPort.Write(new byte[] { 48 }, 0, 1);
break;
}
};
But still nothing works.
Please help me.
Thanks.
|
|
|
|
|
Member 10850253 wrote: ComPort.Close();
ComPort.Write(new byte[] { 48 }, 0, 1);
You're trying to write to the ComPort after you've closed it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I also tried this:
SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);
void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{
if (e.Reason == SessionEndReasons.Logoff)
{
\\Code
}
}
And I still can't get it working.
Can someone please help me?
Thanks.
|
|
|
|
|
Have you tried these suggestions[^]?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi All !
I using DataReader for Sum Value of Column :
double Sum = 0.00;
OleDbDataReader dr=null;
string strSum =@"Select SUM(Val1 + Val2 + Val3) as Total from myTable Where year="+Convert.int32(txtyear.Text);
try
{
cnn = new OleDbConnection(strcn);
cnn.Open();
OleDbCommand cmd = new OleDbCommand(strSum,cnn);
dr = cmd.ExecuteReader();
if (dr.Read())
{
int ordinal = dr.GetOrdinal("Total");
txtFasl_Two_Msvb.Text = dr.GetDouble(ordinal).ToString();
}
else
{
txtSum.Text = "0";
}
}
catch(Exception exp)
{
MessageBox.Show(exp.ToString());
}
Sum = Convert.ToDouble(txtSum.Text);
return Sum;
I want to put Zero for Sum if DataReader has no row or Value , but it throw to an exception .
How can handle it ?
Thanks
|
|
|
|
|
There is so much to say about these few lines of code.
First, this does not compile, due to the third line.
Basically you are:
- reading a double value from your database.
- make a string out of this value if found, and set the Text property of a TextBox from the result ; if not found, you put a "0" string in another TextBox.
- then you convert it back to a double from the TextBox that can only be "0".
Moreover, as your WHERE clause restricts the result to one line, you should be using ExecuteScalar instead of ExecuteReader .
When you want to work with numbers, then keep up with the numbers. The only moment when you have to make a string from your number is when you want to present it to the user. Every design moving back and forth from number to string is a terrible practice and should be avoided at any time.
Also, when dealing with Disposable objects (OleDbCOnnection and OleDbCommand), you should use a using block to make sure you release all resources when you do not need them anymore.
At the end of your method, you return a double. This function should only deal with computing the result. Displaying it in a TextBox should be done elsewhere.
A more appropriate implementation could be:
double result = 0;
string strSum = "SELECT SUM(Val1 + Val2 + Val3) AS Total FROM myTable WHERE year=@year";
int year;
if (!int.TryParse(txtyear.Text, out year)) {
throw new ArgumentException("Entered text is not convertible to a valid integer.");
}
using (OleDbConnection cnn = new OleDbConnection(strcn)) {
cnn.Open();
using (OleDbCommand cmd = new OleDbCommand(strSum, cnn)) {
cmd.Parameters.AddWithValue("@year", year);
try {
result = (double)cmd.ExecuteScalar();
}
catch (SqlException ex) {
MessageBox.Show(string.Format("{0}{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace));
}
}
}
return result;
There are two kinds of people in the world: those who can extrapolate from incomplete data.
|
|
|
|
|
Hi All
I want to show a big Number in TextBox , so I define it to "double":
double Sum = 0.00;
for (int j = 0; j < 10; j++)
{
for (int i = 0; i < dgVal.RowCount; i++)
{
Sum += Convert.ToDouble(dgVal[j + 1, i].Value);
}
}
txtSum.Text = Sum.ToString();
but my output is : 1.00000000010833E+15 that's a scientific Number , plz Help me , How to show the "Sum" in form Like : 123456789012345678 about 18 digit.
thanks
|
|
|
|
|
Something like
Sum.ToString("F30").TrimEnd("0".ToCharArray());
|
|
|
|
|
|
You can't use a double to show 18 digits: it only shows 15 significant digits (though it uses 17 internally).
If you want 18 digit precision, then you need to use an Int64 (or long ) value, which can hold up to 9,223,372,036,854,775,807 - 19 digits.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
A bit less than 17 even, approximately 15.9545897702 (it's probably a bad idea to measure it in decimal digits, 0.954etc of a digit is confusing).
|
|
|
|
|
Hi,
I have inherited what I would call a badly designed database using SQL Server. At the moment the application that uses the database has an Access 97 front-end and with XP now being end of life, I have been tasked with creating a new application to replace Access 97.
I am looking quite a bit into the project architecture to future proof the application and also for best practices. I have been reading into using a 3-tier architecture - DAL, BLL and UI.
I originally started looking into using EF but it doesn't seem overly compatible with my database as there are quite a few tables that don't have PK's and we already have a lot of stored procedures that will be used rather than directly to the table. I have currently decided that I will use ADO.Net but can't help but feel that is a bad decision.
I really have a couple of questions here -
1 - What project architecture do people generally use these days and what is best practice, can you provide me with some examples?
2 - If I continue down the ADO.Net route do I create different classes for the different Stored Procedures that are used?
3 - Am I making the right decision using ADO.Net?
Any help/advice/links are greatly appreciated.
|
|
|
|
|
EF also supports sprocs[^].
JammoD87 wrote: 1 - What project architecture do people generally use these days and what is
best practice, can you provide me with some examples? EF is the most mentioned out-of-the-box ORM's around here. LINQ is mainly something used on collections, and sometimes there's a mention of NHibernate. Most go for some custom implementation tough.
JammoD87 wrote: 2 - If I continue down the ADO.Net route do I create different classes for the
different Stored Procedures that are used? That's possible, if you'd want to.
JammoD87 wrote: 3 - Am I making the right decision using ADO.Net? Yes.
Well, EF makes a close second; I don't have hands-on experience with it, but heard good things about it. ADO has been there since .NET, and there's a lot of documentation on the subject. I'd say it is the path that has proven to work, with EF looking as a nice new alternative.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for that, there's some helpful advice fhere!
|
|
|
|
|
If you are already using ADO.net I wouldn't suggest you to go with EF. If you wish to use EF you can use it You can even use your existing stored procedures if you want but may have to do some changes. The decision with EF or ADO.net depends on other factors also like
1) if you want better performance and working on huge data then go with ADO.net.
2) Whatever you are comfortable with. If you have a very good expertise in ADO.net then go with ADO.net or if you have very good expertise in EF then go with EF.
Instead of a 3-tier architecture I would suggest you to try GUI Architectural patterns either MVVM or MVC depending on the type of the application.
If you want to use 3 tier architecture then there may be more layers required to have separation of concerns e.g:- for cross cutting concerns etc.
|
|
|
|
|
Hello. I have this small application in which I am using some open source dlls. Whenever I build my project, git notifies that I have new files ("git status" command in Git Bash). Now I tried to ignore these *.exe, *.dll, *.pdb and *.xml files in .gitignore but in vain (I don't know where to put it...so I placed mutiple copies of it, in different locations).
How do use I git properly so that it recognize only the *.cs files and not all the EXEs and other stuff. Thanks for any pointer.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
|
I have one Form with panel added to it. I have separate user control which display the rectangle.Now I have to add this user control to the form panel.I added it, but it not showing the rectangle.
|
|
|
|
|
This does not make any sense.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Your reply is perfect. Especially the joke about the 10 types of people.
|
|
|
|
|
How are you drawing the rectangle? Without seeing the code in the user control it's just about impossible to tell you anything useful.
|
|
|
|
|
This is either a Windows Forms or WPF issue.
Not really C#
Please use the correct forum.
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
|
|
|
|