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
Loading
Niradhip ChakrabortyPosted Apr 20, 2009, 7:43 AM
string
strS1= ""; in the beginning(check What Vimal says).This will alocate a memory space for strS1 variable.
SreekanthPosted Apr 20, 2009, 6:53 AM
ididnt understand ur question?
but..
if ur trying to ;
select * from TABle where primarykey=Response.Write(str1)
is error.
selcet * from table where key="+str1+" is ok.
But Imnot sure whther u can take select statement without closing datareader.
So if ur tryng to get each seleratestr1 value and then corresnding values other details from another table..
better use dataset .
Vimal KandasamyPosted Apr 20, 2009, 6:52 AM
Its because u assign value inside the while loop only...
Initially assign value for str1.it will solve your problem
Ex:
string str1="";