Click here to Skip to main content
15,906,301 members
Home / Discussions / C#
   

C#

 
AnswerRe: when to use SerializationAttribute Pin
BobJanova22-Nov-11 5:03
BobJanova22-Nov-11 5:03 
QuestionMaximum number of columns for a ListView control Pin
Kalvin @ Work21-Nov-11 8:57
Kalvin @ Work21-Nov-11 8:57 
AnswerRe: Maximum number of columns for a ListView control Pin
Kalvin @ Work21-Nov-11 9:27
Kalvin @ Work21-Nov-11 9:27 
GeneralRe: Maximum number of columns for a ListView control Pin
Mark Salsbery21-Nov-11 9:34
Mark Salsbery21-Nov-11 9:34 
AnswerRe: Maximum number of columns for a ListView control Pin
Mark Salsbery21-Nov-11 9:30
Mark Salsbery21-Nov-11 9:30 
GeneralRe: Maximum number of columns for a ListView control Pin
Luc Pattyn21-Nov-11 11:48
sitebuilderLuc Pattyn21-Nov-11 11:48 
AnswerRe: Maximum number of columns for a ListView control Pin
DaveyM6921-Nov-11 12:53
professionalDaveyM6921-Nov-11 12:53 
GeneralRe: Maximum number of columns for a ListView control Pin
Dan Mos21-Nov-11 22:17
Dan Mos21-Nov-11 22:17 
AnswerRe: Maximum number of columns for a ListView control Pin
SilimSayo22-Nov-11 6:22
SilimSayo22-Nov-11 6:22 
Questioninsert Data to a MultiColumn ListView By ComboBox Items Pin
nassimnastaran21-Nov-11 4:49
nassimnastaran21-Nov-11 4:49 
AnswerRe: insert Data to a MultiColumn ListView By ComboBox Items Pin
Matt U.21-Nov-11 6:49
Matt U.21-Nov-11 6:49 
QuestionDifference in webconfig "authorization" in .net framework 1.1 and 4.0 Pin
maithilym20-Nov-11 23:50
maithilym20-Nov-11 23:50 
AnswerRe: Difference in webconfig "authorization" in .net framework 1.1 and 4.0 Pin
OriginalGriff21-Nov-11 6:21
mveOriginalGriff21-Nov-11 6:21 
GeneralRe: Difference in webconfig "authorization" in .net framework 1.1 and 4.0 Pin
maithilym21-Nov-11 17:04
maithilym21-Nov-11 17:04 
GeneralRe: Difference in webconfig "authorization" in .net framework 1.1 and 4.0 Pin
Pete O'Hanlon21-Nov-11 22:02
mvePete O'Hanlon21-Nov-11 22:02 
Questionmvc3 custom authentication provider asp.net online list Pin
samwood201120-Nov-11 23:17
samwood201120-Nov-11 23:17 
AnswerRe: mvc3 custom authentication provider asp.net online list Pin
Pete O'Hanlon21-Nov-11 0:44
mvePete O'Hanlon21-Nov-11 0:44 
QuestionTDES Pin
BAZJAK20-Nov-11 21:38
BAZJAK20-Nov-11 21:38 
AnswerRe: TDES Pin
JF201520-Nov-11 22:41
JF201520-Nov-11 22:41 
GeneralRe: TDES Pin
BAZJAK22-Nov-11 0:05
BAZJAK22-Nov-11 0:05 
AnswerRe: TDES Pin
phil.o21-Nov-11 10:23
professionalphil.o21-Nov-11 10:23 
QuestionProblem with SQLDataReader and Insert command Pin
CCodeNewbie20-Nov-11 6:39
CCodeNewbie20-Nov-11 6:39 
Greetings Gurus,

Could you offer some advice/help please?

I am trying to read a SQL db for a specific value and add it in if not found. I have more-or-less got the procedure working but the DataReader recognises that the value exists then goes and adds it back in twice anyway.
C#
try
{
    string c = System.Environment.MachineName;
    string Domain = System.Net.Dns.GetHostName();
    ManagementObjectSearcher SerialNo = new 
    ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM 
    Win32_SystemEnclosure");
    foreach (ManagementObject querySN in SerialNo.Get())
        {
        string SN = (querySN["SerialNumber"].ToString());
        string SysIdent = c + SN + "@" + Domain;
        
        SqlConnection conn1 = new SqlConnection("User id = a; 
        password = b; server=c; database=d;connection timeout=30");
        SqlCommand selectname = new SqlCommand("SELECT FullName
        FROM dbo.tablename", IdentSys);
        IdentSys.Open();
        SqlDataReader GetIdnt = selectname.ExecuteReader();
        while (GetIdnt.Read())
            {
            string Names = Convert.ToString(GetIdnt["FullName"]);
                {
                if (Names != SysIdent)
                    {
                    SqlConnection conn2 = new SqlConnection("User id = a;
                    password = b; server=c; database=d;connection timeout=30");
                    SqlCommand newname = new SqlCommand("INSERT
                    INTO dbo.SysIdent(FullName) VALUES(@FullName)", InsertSys);
             newname.Parameters.AddWithValue("@FullName",SysIdent);
                    InsertSys.Open();
                    newname.ExecuteNonQuery();
                    InsertSys.Close();
                    }
                }
            }
    GetIdnt.Close();
    }
}
catch (Exception f)
{
Console.WriteLine(f.ToString());
}


Could you advise what I am doing wrong please?
AnswerRe: Problem with SQLDataReader and Insert command Pin
Dan Mos20-Nov-11 7:49
Dan Mos20-Nov-11 7:49 
GeneralRe: Problem with SQLDataReader and Insert command Pin
CCodeNewbie20-Nov-11 9:13
CCodeNewbie20-Nov-11 9:13 
GeneralRe: Problem with SQLDataReader and Insert command Pin
Dan Mos20-Nov-11 9:56
Dan Mos20-Nov-11 9:56 

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.