Click here to Skip to main content
15,909,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
While I am adding a record I have defined the Id value.But every time it takes the default guid value..means only 00000000-0000-0000-0000-000000000000.Hence in db it store two data with same id.again when i delete the added record all the record are deleted as id=00000000-0000-0000-0000-000000000000,Can you please tell me how to avoid this prolem so that while adding a record it will store the data with some new guid values..
my codes are as follows

C#
//Add Buttoon for adding record
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Guid id = new Guid();
        string Id = id.ToString();
        Member member = new Member();
      
        member.ID = Id;
        member.MemberID = int.Parse(txtMemberID.Text);
        member.ReceiptNo = txtReceiptNo.Text;
        member.SurName = txtSurName.Text;
        member.Name = txtName.Text;
        member.DateOfBirth = txtDateOFBirth.Text;
if (memberService.AddMember(member) == true)
            LoadData();

//load data method as follows
public void LoadData()
    {
        List<Member> members = memberService.GetAllMembers();
        gvMembers.DataSource = members;
        gvMembers.DataBind();
Posted

 
Share this answer
 
Comments
DamithSL 12-Dec-14 10:01am    
beat me to it :) 5wd!
call
C#
Guid id = Guid.NewGuid();


Quote:
new Guid() makes an "empty" all-0 guid (00000000-0000-0000-0000-000000000000 is not very useful).

Guid.NewGuid() makes an actual guid with a unique value, what you probably want.

http://stackoverflow.com/questions/11938151/guid-newguid-vs-new-guid[^]
 
Share this answer
 
v2
see the link here, if you want to covert guid to string, why my last ans downvoted i dont know, i even practically done this

http://stackoverflow.com/questions/1700361/how-to-convert-a-guid-to-a-string-in-c[^]
 
Share this answer
 
Hi you have to typecast or can say parse the value like this ,

String guid = System.Guid.NewGuid().ToString();

by this you will get guid value in string form and can save to relevent field you require.
 
Share this answer
 
Comments
deepankarbhatnagar 12-Dec-14 12:40pm    
why downvote plz explain

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900