how to hold data from the database

Apr 20 2009 6:34 AM
Hi

i write the code for reading the data from the database its is working fine. the code for reading data is

 public void getuid()
    {
        string str1;
        SqlConnection con = new SqlConnection("server=.;database=Ckom;uid=sa");
        SqlCommand cmd = new SqlCommand("select max(UserID) uid from UserDetail",con);
        SqlDataReader ddDr;
        con.Open();
        ddDr=cmd.ExecuteReader();
        while (ddDr.Read())
        {
            str1 = ddDr["uid"].ToString();
            Response.Write(str1]);
        }       
    }

if i write Response.write(str1) method inside the while loop its working fine
but if i used same Response.write(str1) its showing me error that  Use of unassigned local variable 'str1'

please help me i need the value
because with that value i need to read data from other table

please help me


Answers (3)