Click here to Skip to main content
15,908,115 members
Home / Discussions / C#
   

C#

 
GeneralRe: Live Data in an application Pin
vjs244515-Oct-11 6:34
vjs244515-Oct-11 6:34 
GeneralRe: Live Data in an application Pin
Mark Salsbery15-Oct-11 6:55
Mark Salsbery15-Oct-11 6:55 
GeneralRe: Live Data in an application Pin
vjs244515-Oct-11 14:21
vjs244515-Oct-11 14:21 
AnswerRe: Live Data in an application Pin
BobJanova16-Oct-11 22:52
BobJanova16-Oct-11 22:52 
QuestionUML Class Diagram Pin
PozzaVecia14-Oct-11 21:14
PozzaVecia14-Oct-11 21:14 
AnswerRe: UML Class Diagram Pin
Abhinav S15-Oct-11 3:20
Abhinav S15-Oct-11 3:20 
GeneralRe: UML Class Diagram Pin
PozzaVecia15-Oct-11 5:32
PozzaVecia15-Oct-11 5:32 
QuestionDisposing of values in foreach loop Pin
CCodeNewbie14-Oct-11 9:39
CCodeNewbie14-Oct-11 9:39 
Greetings Gurus,

The problem:
"The variable name '@Tstamp' has already been declared. Variable names must be unique within a query batch or stored procedure."

Guesstimate cause:
The data in the variable '@Tstamp' is not being released

The code
C#
SqlCommand inst = new SqlCommand("INSERT INTO dbo.DrvInfo(Tstamp)" +
                                                        "VALUES (@Tstamp)", DrvInfo);
            DriveInfo[] drives = DriveInfo.GetDrives();
                foreach (DriveInfo d in drives)
                {
                Console.WriteLine(d.Name);
                Console.WriteLine(d.DriveType);
                if (d.IsReady == true)
                {
                    string label = d.VolumeLabel;
                    if (label.Length == 0)
                        label = "No Label";
                            Console.WriteLine(d.VolumeLabel);
                            Console.WriteLine(d.AvailableFreeSpace / 1024000000);
                            Console.WriteLine(d.TotalSize / 1024000000);
                            DrvInfo.Open();
                            inst.Parameters.Add("@Tstamp", SqlDbType.NVarChar, 50).Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InstalledUICulture);// the other values follow this but I am using this as an example
           inst.ExecuteNonQuery();
                            DrvInfo.Close();
                            }
                    else
                    Console.WriteLine("uh oh");
               }


The question:
In iterating through the values of the foreach, how do I dispose of the first set of collected data so that the next set can be written to the table?

Can you help please? Do I need to declare each variable as "Nothing" before restarting the loop?
AnswerRe: Disposing of values in foreach loop Pin
Ian Shlasko14-Oct-11 9:46
Ian Shlasko14-Oct-11 9:46 
GeneralRe: Disposing of values in foreach loop Pin
CCodeNewbie14-Oct-11 11:05
CCodeNewbie14-Oct-11 11:05 
GeneralRe: Disposing of values in foreach loop Pin
Ian Shlasko14-Oct-11 11:45
Ian Shlasko14-Oct-11 11:45 
GeneralRe: Disposing of values in foreach loop Pin
CCodeNewbie14-Oct-11 11:50
CCodeNewbie14-Oct-11 11:50 
GeneralRe: Disposing of values in foreach loop Pin
BobJanova16-Oct-11 22:54
BobJanova16-Oct-11 22:54 
AnswerRe: Disposing of values in foreach loop Pin
PIEBALDconsult14-Oct-11 11:11
mvePIEBALDconsult14-Oct-11 11:11 
GeneralRe: Disposing of values in foreach loop Pin
CCodeNewbie14-Oct-11 11:16
CCodeNewbie14-Oct-11 11:16 
GeneralRe: Disposing of values in foreach loop Pin
PIEBALDconsult14-Oct-11 11:47
mvePIEBALDconsult14-Oct-11 11:47 
GeneralRe: Disposing of values in foreach loop Pin
CCodeNewbie14-Oct-11 11:56
CCodeNewbie14-Oct-11 11:56 
GeneralRe: Disposing of values in foreach loop Pin
PIEBALDconsult14-Oct-11 12:04
mvePIEBALDconsult14-Oct-11 12:04 
GeneralRe: Disposing of values in foreach loop Pin
CCodeNewbie14-Oct-11 21:50
CCodeNewbie14-Oct-11 21:50 
GeneralRe: Disposing of values in foreach loop Pin
PIEBALDconsult15-Oct-11 4:22
mvePIEBALDconsult15-Oct-11 4:22 
AnswerRe: Disposing of values in foreach loop Pin
Luc Pattyn14-Oct-11 15:12
sitebuilderLuc Pattyn14-Oct-11 15:12 
GeneralRe: Disposing of values in foreach loop Pin
PIEBALDconsult14-Oct-11 16:43
mvePIEBALDconsult14-Oct-11 16:43 
AnswerRe: Disposing of values in foreach loop Pin
Luc Pattyn14-Oct-11 16:58
sitebuilderLuc Pattyn14-Oct-11 16:58 
QuestionNeed help reading 64bit registry keys from a 32bit application, remotely Pin
turbosupramk314-Oct-11 7:01
turbosupramk314-Oct-11 7:01 
AnswerRe: Need help reading 64bit registry keys from a 32bit application, remotely Pin
André Kraak14-Oct-11 8:55
André Kraak14-Oct-11 8:55 

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.