Link to home
Start Free TrialLog in
Avatar of dshi15
dshi15Flag for United States of America

asked on

How to use Guid datatype in C#

Hi Expert,

I like to insert data to a column which are Guid datatype.

I like to insert two records

@p_Student_ID = new Guid("1A1A1A1A-AD43-499E-839F-32E31A1A1A1A")
@p_Student_ID = new Guid("1B1B1B1B-AD43-499E-839F-32E31B1B1B1B")

Can I declare a variable and assign a value later like string?

String S1="";

If (i==0)
S1='Test1;
Else if (i==1)
S1='Test2;

Thanks in advance
Avatar of p_davis
p_davis

if its local variable for a method, you would need to initialize it but if it is a class member you could assign a value at any time.

you can generally assign values at any given time but you cannot access before a value is assigned...
 
im not sure if i have understood your question so if you need more information, just let me know
Avatar of dshi15

ASKER

It is class member, but how I can declare it and assign value in the method,

Public Class ABC
{
Guid  Student_ID =New Guid("");


Public void DEF()
{

for (int i = 0; i <= 1; i++)
{

     If (i==0)
         Student_ID =new Guid("1A1A1A1A-AD43-499E-839F-32E31A1A1A1A")    
     Else if (i==1)
         Student_ID =new Guid("1B1B1B1B-AD43-499E-839F-32E31B1B1B1B")


     other code here



        cmd.Parameters.AddWithValue("@p_Student_ID", Student_ID);


the syntax isn't correct, what is correct syntax to declare this Guid variable and assign these value to it?

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial