|
I have a a multi-purpose application that I am working with. 3 Different forms, one form has log in validation and the another has DateTimePickers. I threw a button on the parent form just to compare saved settings, when I set a Time in DTP say for 11:30 PM and the close that form and go back to the parent form, the DTP Value that I saved doesn't actually get saved till I close my application and re-open it, so I can't compare my alarm times unless I close the application and re-open it. How can I get the form to refresh to the most updated variable that is being stored in my settings?
|
|
|
|
|
Herboren wrote: How can I get the form to refresh to the most updated variable that is being stored in my settings?
Doesn't the settings-class provide a Reload[^]-method? How did you bind to the ApplicationSetting?
Bastard Programmer from Hell
|
|
|
|
|
Could you please clarify:
1. are you working in WinForms, WPF ... or ?
2. what strategy for saving the DateTime(s) you pick are you using now: Serialization ? Application.Settings ? Registry ?
3. you imply you are setting "alarm:" could you say a bit more about the purpose of your application and its 3-form design ?
best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
modified 22-Sep-11 11:53am.
|
|
|
|
|
Greetings Gurus...
If you could spare a moment..?
The following code is an attempt to retrieve the contents of the Windows Application event log and upload the data to a SQL server.
I am getting 2 errors though and was hoping someone could tell me why the errors are occurring.
Error 1: "A namespace does not directly contain members such as fields or methods" at the line that reads
" SysMonConn.Open();" in bold
Error 2: "Type or namespace definition, or end-of-file expected" at the closing bracket.
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Data.SqlClient;
namespace ConsoleApplication3
{
class Program
{
public static void Main();
string logType = "Application";
EventLog ev = new EventLog(logType, System.Environment.MachineName);
EventLogEntry Entry = ev.Entries;
SqlConnection SysMonConn = new SqlConnection(@"Provider = sqloledb.1" +
"Source = 192.168.x.y,1433" +
"Database = EventLogs" +
"Trusted_Connection=yes;" +
"user id=a;" +
"password=b;" +
"connection timeout=30;");
}
SysMonConn.Open();
SqlCommand SMCommand = SysMonConn.CreateCommand();
SMCommand.CommandText = "INSERT INTO dbo.EventTable(Category, ComputerName," +
"Message, SourceName, TimeWritten,Type, UserName)";
SMCommand.Parameters.Add("@Category", System.Data.SqlDbType.NVarChar, 50) = Entry.Category;
SMCommand.Parameters.Add("@ComputerName", System.Data.SqlDbType.NVarChar, 50) = Entry.MachineName;
SMCommand.Parameters.Add("@Message", System.Data.SqlDbType.NVarChar, 250) = Entry.Message;
SMCommand.Parameters.Add("@SourceName", System.Data.SqlDbType.NVarChar, 50) = Entry.Source;
SMCommand.Parameters.Add("@TimeWritten", System.Data.SqlDbType.NVarChar, 50) = Entry.TimeWritten;
SMCommand.Parameters.Add("@Type", System.Data.SqlDbType.NVarChar, 50) = Entry.EntryType;
SMCommand.Parameters.Add("@UserName", System.Data.SqlDbType.NVarChar, 50) = Entry.UserName;
ev.Close();
}
}
Any assistance greatly appreciated
|
|
|
|
|
your curly brackets are all wrong, you need one when opening Main (rather than a semi-colon), and the matching one is below ev.Close(); , so the one in front of SysMonConn.Open() should be removed.
If you put the curlies right, the right indentation of your code would ensue automatically (at least in real IDE's such as Visual Studio); if it looks almost right at the moment, it tells me you have been adding/removing tabs yourself.
|
|
|
|
|
Um - perhaps I'm missing something, but you have an extraneous } directly before the bolded line which is closing Main()....what follows is therefore outside a method and hence will not fly - I'd have thought you'd have spotted that though!
C# has already designed away most of the tedium of C++.
|
|
|
|
|
Your declaration of Main() is terminated with a semi-colon so becomes a null method. You also have a spurious closing brace '}' just before SysMonConn.Open(); .
|
|
|
|
|
Hi Luc, RichardG & RichardM,
Thank you for the quick responses.
I had tried the fixes you suggested but get (mainly) 2 other errors when I reformat the code:-
public static void Main()
{
string logType = "Application";
EventLog ev = new EventLog(logType, System.Environment.MachineName);
EventLogEntry Entry = ev.Entries;
SqlConnection SysMonConn = new SqlConnection(@"Provider = sqloledb.1" +
"Source = 192.168.x.y,1433" +
"Database = EventLogs" +
"Trusted_Connection=yes;" +
"user id=a;" +
"password=b;" +
"connection timeout=30;");
SysMonConn.Open();
SqlCommand SMCommand = SysMonConn.CreateCommand();
SMCommand.CommandText = "INSERT INTO dbo.EventTable(Category, ComputerName," +
"Message, SourceName, TimeWritten,Type, UserName)";
SMCommand.Parameters.Add("@Category", System.Data.SqlDbType.NVarChar, 50) = Entry.Category;
SMCommand.Parameters.Add("@ComputerName", System.Data.SqlDbType.NVarChar, 50) = Entry.MachineName;
SMCommand.Parameters.Add("@Message", System.Data.SqlDbType.NVarChar, 250) = Entry.Message;
SMCommand.Parameters.Add("@SourceName", System.Data.SqlDbType.NVarChar, 50) = Entry.Source;
SMCommand.Parameters.Add("@TimeWritten", System.Data.SqlDbType.NVarChar, 50) = Entry.TimeWritten;
SMCommand.Parameters.Add("@Type", System.Data.SqlDbType.NVarChar, 50) = Entry.EntryType;
SMCommand.Parameters.Add("@UserName", System.Data.SqlDbType.NVarChar, 50) = Entry.UserName;
ev.Close();
}
}
}
I now get:
Error 1 "Cannot implicitly convert type 'System.Diagnostics.EventLogEntryCollection' to 'System.Diagnostics.EventLogEntry'" on the bold line ev.Entries
Errors 2,4,6,8,10,12,14 "The left-hand side of an assignment must be a variable, property or indexer" on all the lines
SMCommand.Parameters.Add("@xxxxx", System.Data.SqlDbType.NVarChar, 50)
Errors 3,5,7,9,11,13,15 "Cannot implicitly convert type 'string' to 'System.Data.SqlClient.SqlParameter'" on all the lines Entry.xxxxx
Please pardon my ignorance but I learning by example, trial-and-error and looking through other's code so I don't always understand why these errors occur.
Thanks for your patience...
|
|
|
|
|
I have a number of suggestions for you:
1.
Read the error messages carefully, most of the time they make perfect sense, however each word counts.
2.
Focus on the first message first; oftentimes the other ones are a result of the earlier mistakes in your code.
3.
If you're new to something, start with the smallest amount of code that could compile and run (and maybe do nothing much); once it compiles and runs, start adding stuff; keep compiling and running, never just enter lots of code, then feel completely lost when tons of errors appear.
4.
The best way to learn some new language or technology, is by choosing, buying and studying a book on the subject; you can and should add some experimentation to it, but experiments alone are no substitute for studying a real book.
|
|
|
|
|
Hi Luc,
In response,
1. I have read the messages, Googled them, and been through dozens of webpages, blog pages and forums trying to find a solution. The reason I posted to this esteemed forum is because I had still not been able to find an answer to my problem
2. See 1) above. If you don't know and can't find the meaning of the first message it won't help resolve the second message
3. I have been through the c# (and c++) tuts a few times, informative as they are they can't prepare you for everything you may need/want to do. My "Hello World" code runs perfectly.
4. I agree, but even if you buy and study hundreds of "Teach Yourself French" books eventually you are going to have to talk to a Frenchman. D'accord?
|
|
|
|
|
I should have included:
-1. keep an open mind; this includes: the compiler is probably right, the programmer most likely made a mistake.
0. apply logic reasoning.
example:
Entry = ev.Entries;
even when the compiler would agree (it doesn't), I as a reader would protest, as the LHS is singular and the RHS is plural.
|
|
|
|
|
Thank you for your patience and somewhat cryptic answers Luc but,
-1. It is (almost) always safe to assume that the programmer has made a mistake. If however he does not know where the mistake is he cannot fix it. Thus he turns to better programmers.
0. Logic is great as long as you can think like the compiler does. I can think in vba but c# is still a learning process. Unfortunately they don't use the same logic<>syntax.
example:
EventLogEntry Entry = ev.Entry; = 'System.Diagnostics.EventLog' does not contain a definition for 'Entry' (same applies to Entries = Entries)
Thank you for your advice Luc but I am just not understanding what you are trying to tell me.
|
|
|
|
|
Look again (closely) at this message: Error 1 "Cannot implicitly convert type 'System.Diagnostics.EventLogEntryCollection' to 'System.Diagnostics.EventLogEntry'"
What is it saying in the most basic terms: cannot convert a [System.Diagnostics.EventLog]EntryCollection (the return value of ev.Entries ) to [System.Diagnostics.EventLog]Entry - OK, you are trying to convert an EntryCollection (a collection is obviously plural) to an Entry (singular). So by changing the destination of your assignment to be some type of Collection (probably an EntryCollection) would maybe get rid of that error. Recompile and see how many of the other errors still exist and follow the same process again. This can be done quite easily without the use of Google just by checking the documentation[^].
You may like to reread Luc's previous suggestion as his logical approach to problem solving will serve you well.
|
|
|
|
|
Maybe it's just a basic misunderstanding of the assignment operator ("="). It assigns the return value of the right hand expression to the return value of the left hand expression. Let's put it in symbols: Target <- Source .
Further down, the lines SMCommand.Parameters.Add() = Entry.Category each call a method Add() and immediately replace its return value by Entry.Whatever . I can only guess, but maybe you want it to behave the other way round.
Add() returns an SqlParameter . Maybe you want to store that via
Entry.Message = Add("@Message", System.Data.SqlDbType.NVarChar, 250).ToString(); But even then, I doubt that EventLogEntry.Category and EventLogEntry.EntryType would accept a string . In this case, you would have to create some kind of conversion.
Ciao,
luker
|
|
|
|
|
i have one issue
whenever selecting radio button ,print option should come by using java script. if any one having solution please let me know.
|
|
|
|
|
You might have better luck posting a JavaScript question in the JavaScript forum. This is C#, and the similarities are superficial.
|
|
|
|
|
this code not sending email Why? please help me
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace Web11
{
public partial class WebSendMail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
MailMessage Mail = new MailMessage();
Mail.To.Add("AotherEmail@hotmail.com");
Mail.From = new MailAddress("MyEmail@hotmail.com");
Mail.Subject = "ASp.net";
Mail.Body = " hi I want Help";
SmtpClient smt = new SmtpClient("smtp.hotmail.com");
smt.Send(Mail);
Response.Write("Email Was Send");
}
catch (Exception ex)
{
Response.Write(" Email Invalid"+ex.Message );
}
}
}
}
|
|
|
|
|
I dont know.
Why dont you
1) Try and debug the code yourself
2) Check the Host name and credentials are correct
3) Post error messages
|
|
|
|
|
Use network cardentials
NetworkCredential authinfo = new NetworkCredential("id", "password");
smtp.UseDefaultCredentials = false;
smtp.Credentials = authinfo;
|
|
|
|
|
Unless they've changed it Hotmail doens't allow relaying, so you can't use it to send emails. You'll need a server that does permit relays.... IIRC, none of the big web-mail providers allow it for obvious reasons
C# has already designed away most of the tedium of C++.
|
|
|
|
|
Enterprise Library ExecuteDataSet method not setting Output parameter value.
The value of output parameter is always null.
using (DbCommand cmd = db.GetStoredProcCommand("s_sProcName"))
{
DataSet ds = new DataSet()
db.AddInParameter(cmd, "@p_sFoo", DbType.String, "Bar");
db.AddOutParameter(cmd, "@po_iOut", DbType.Int32, 4)
ds = db.ExecuteDataSet(cmd);
}
How can i get value of Output parameter?
Can any one please !!
|
|
|
|
|
You are actually giving it an output value in your SP aren't you? That one's caught me out before!
C# has already designed away most of the tedium of C++.
|
|
|
|
|
I need something like this:
private void LoadFieldsNames(string table_name)
{
string[] fields = new string[100];
switch (table_name)
{
case "step_result":
fields = {"ID", "UUT_RESULT", "STEP_PARENT", "LOOP_INDEX", "INTERACTIVE_EXENUM"};
break;
case "uut_result"
fields = {"ID", "STATION_ID", "BATCH_SERIAL_NUMBER", "TEST_SOCKET_INDEX",};
break;
}
comboBoxSelField.Items.AddRange(fields);
}
But i get an error. How can i manage the string propelly?
|
|
|
|
|
try this
private void LoadFieldsNames(string table_name)
{
string[] fields = null;
switch (table_name)
{
case "step_result":
fields = new string[]{"ID", "UUT_RESULT", "STEP_PARENT", "LOOP_INDEX", "INTERACTIVE_EXENUM"};
break;
case "uut_result"
fields = new string[]{"ID", "STATION_ID", "BATCH_SERIAL_NUMBER", "TEST_SOCKET_INDEX"};
break;
}
comboBoxSelField.Items.AddRange(fields);
}
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Thanks a lot - it works!
|
|
|
|
|