Thanks for the good link, Joe! I found out all those "What you did not know's" the hard way over time. Wish I had seen that earlier. :P
On Sep 1, 12:57 pm, Joe Enos <[EMAIL PROTECTED]> wrote: > Check out the following blog: > > http://codewidgets.blogspot.com/2008/05/what-you-did-not-know-about-s... > > If you use the constructor - new TableFields() - it will initialize > all values to their default value. If you skip the constructor, you > have to initialize all members yourself. > > On Aug 31, 7:58 pm, Benj Nunez <[EMAIL PROTECTED]> wrote: > > > > > Hello experts, > > > I recently deployed a project that uses > > a struct and is declared like this: > > > struct TableFields > > { > > public string BadgeNumber; > > public string SSN; > > public string Name; > > } > > > I have 4 methods that use this structure > > as a reference parameter. And these are: > > > InsertRecord(ref TableFields stf) > > UpdateRecord(ref TableFields stf) > > getRecord(string ABadgeNumber, ref TableFields stf) > > getRecordEx(string ASSN, ref TableFields stf) > > > The structure as well as the 4 methods are in a > > file called 'DatabaseManager'. The struct is > > declared outside the class. > > > My MainForm.cs file uses the methods defined in the > > DatabaseManager.cs file. > > > I have a btnSave_Click() event that uses the structure > > to temporarily store the contents of the textboxes like > > so: > > > TableFields tblUser; // notice that no instantiation took place. > > > tblUser.BadgeNumber = SearchbADGENUMBERTextBox.Text; > > tblUser.SSN = sSNTextBox.Text.ToUpper(); > > tblUser.Name = nAMETextBox.Text; > > > ... // validation / search for record if exists go here... > > > dm.InsertRecord(tblUser); > > > Now, here's what my validation code looks like: > > > TableFields field = new TableFields(); // compile error when > > "new ..." is removed. > > if (dm.getRecord(SearchbADGENUMBERTextBox.Text.Trim(), field)) > > { > > MessageBox.Show("Record with BadgeNumber " + > > SearchbADGENUMBERTextBox.Text + " already exists.", > > "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); > > ... > > > } > > > The compiler error I get is: > > > "Use of unassigned local variable 'field'" > > > I just don't understand why at some point, the structure > > needs to be initialized prior to using it. Whereas, I was able > > to use the structure when I want to get the textbox.Text > > values. My assumption is that dm.getRecord might return null > > (since there's a sql call underneath it) and this might > > affect some of the structure's fields. Am I correct? > > Can someone enlighten me on this one? Thank you > > in advance.- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://cm.megasolutions.net/forums/default.aspx -~----------~----~----~----~------~----~------~--~---
