Click here to Skip to main content
15,889,462 members
Home / Discussions / C#
   

C#

 
GeneralSettings not saving correctly. Pin
Herboren21-Sep-11 7:56
Herboren21-Sep-11 7:56 
GeneralRe: Settings not saving correctly. Pin
Eddy Vluggen21-Sep-11 9:51
professionalEddy Vluggen21-Sep-11 9:51 
GeneralRe: Settings not saving correctly. Pin
BillWoodruff22-Sep-11 4:18
professionalBillWoodruff22-Sep-11 4:18 
QuestionNamespace problem Pin
CCodeNewbie21-Sep-11 5:45
CCodeNewbie21-Sep-11 5:45 
AnswerRe: Namespace problem Pin
Luc Pattyn21-Sep-11 6:12
sitebuilderLuc Pattyn21-Sep-11 6:12 
AnswerRe: Namespace problem Pin
RichardGrimmer21-Sep-11 6:12
RichardGrimmer21-Sep-11 6:12 
AnswerRe: Namespace problem Pin
Richard MacCutchan21-Sep-11 6:16
mveRichard MacCutchan21-Sep-11 6:16 
GeneralRe: Namespace problem Pin
CCodeNewbie21-Sep-11 6:47
CCodeNewbie21-Sep-11 6:47 
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:-

C#
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...
AnswerRe: Namespace problem Pin
Luc Pattyn21-Sep-11 7:09
sitebuilderLuc Pattyn21-Sep-11 7:09 
GeneralRe: Namespace problem Pin
CCodeNewbie21-Sep-11 7:24
CCodeNewbie21-Sep-11 7:24 
AnswerRe: Namespace problem Pin
Luc Pattyn21-Sep-11 7:34
sitebuilderLuc Pattyn21-Sep-11 7:34 
GeneralRe: Namespace problem Pin
CCodeNewbie21-Sep-11 7:48
CCodeNewbie21-Sep-11 7:48 
GeneralRe: Namespace problem Pin
Richard MacCutchan21-Sep-11 8:41
mveRichard MacCutchan21-Sep-11 8:41 
GeneralRe: Namespace problem Pin
lukeer21-Sep-11 21:00
lukeer21-Sep-11 21:00 
QuestionJava script -Print Pin
kathyani21-Sep-11 1:27
kathyani21-Sep-11 1:27 
AnswerRe: Java script -Print Pin
Pete O'Hanlon21-Sep-11 1:36
mvePete O'Hanlon21-Sep-11 1:36 
QuestionHotMail in ASP.net Pin
om_metab21-Sep-11 0:15
om_metab21-Sep-11 0:15 
AnswerRe: HotMail in ASP.net Pin
crocks25621-Sep-11 0:30
crocks25621-Sep-11 0:30 
AnswerRe: HotMail in ASP.net Pin
uspatel21-Sep-11 2:00
professionaluspatel21-Sep-11 2:00 
AnswerRe: HotMail in ASP.net Pin
RichardGrimmer21-Sep-11 6:14
RichardGrimmer21-Sep-11 6:14 
QuestionNot getting Output parameter value Pin
Hum Dum20-Sep-11 23:51
Hum Dum20-Sep-11 23:51 
AnswerRe: Not getting Output parameter value Pin
RichardGrimmer21-Sep-11 6:16
RichardGrimmer21-Sep-11 6:16 
QuestionDynamically changing array Pin
jenya720-Sep-11 21:16
jenya720-Sep-11 21:16 
AnswerRe: Dynamically changing array Pin
Blue_Boy20-Sep-11 21:24
Blue_Boy20-Sep-11 21:24 
GeneralRe: Dynamically changing array Pin
jenya720-Sep-11 21:38
jenya720-Sep-11 21:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.