Important alert: (current site time 7/15/2013 7:53:26 AM EDT)
 

winzip icon

Auto insert Guid Datatable

Email
Submitted on: 2/2/2004 1:48:27 PM
By: Jose Fuentes VB MVP  
Level: Advanced
User Rating: By 2 Users
Compatibility: VB.NET
Views: 18545
(About the author)
 
     Ok, I ran into a problem, MS out of some odd wisdom didn't do as you would think with the defaultvalue of a data column. you would think it so simple right? In a database such as SQL server you can set the default value to a function, I can do this with a datacolumn too such as. column1.defaultvalue = system.guid.newguid Though this has an issue, if you use this in a grid you will see as you add new rows that the darn guid is the same. It's calling the newguid only once when setting up the table and it's holding that value static for the rest of the life of the datatable\datacolumn. This goes against common knowlege in how MS does things in other area's, such as the before mentioned SQL server using NewID() will get you a new ID each time. Keep in mind that even other funtions like Now() (which returns current date time) won't work, the defaultvalue will always be the same datetime. So I don't have a solution for the default, I have a different solution. Custom datatable and custom datacolumn classes. You will see in my custom column style that there is a new property called (autogenerateguid)if set to true then it will then set each new row with the correct new guid. Though this is all code based, it works for what I need it to do. It also features the use of an un-documented function and class. NewRowFromBuilder Function System.Data.DataRowBuilder Class I've seen other post's that show to use the rowchanging or positionchanged events in order to do the same thing, this example gets to the source of the newrow creation. What would be better is that if you assign a function that MS would call that function each time instead of this lame static method.
 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 33 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

2/5/2004 12:52:08 PMJose Fuentes

Vote People, doesn't this help anyone out?
(If this comment was disrespectful, please report it.)

 
2/8/2004 10:36:19 PM

this is what i need.
thanks

(If this comment was disrespectful, please report it.)

 
8/19/2004 7:51:50 AMDavid

I use the UniqueIdentifier in MSSQL. I am bringing the info into a datagrid doing some modifications then trying to do an update via a stored procedure and paramaters. I am having trouble getting the guid back to the server I can't find a way to convert the guid back from string. any suggestions??

Thank you in advance for any help you can provide
(If this comment was disrespectful, please report it.)

 
9/12/2004 3:45:37 PM

OK, but where is the example? The compresed file contains only simple and obvious Guid.NewGuid sample project with no conenction with any Datagrid/datatable/etc.etc.

(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.