int nr_dauna = 0;
string selectDauna = "SELECT * FROM dauna WHERE id_client='" + 16 + "'";
SqlCommand executaSelectDauna = new SqlCommand(selectDauna, conn);
SqlDataReader rdr_dauna = executaSelectDauna.ExecuteReader();
rdr_dauna.Read();
nr_dauna = Convert.ToInt32(rdr_dauna["nr_dauna"]);
rdr_dauna.Close();
MessageBox.Show(nr_dauna.ToString());
It's sth wrong? Or maybe there is another way of reading database info?Thanks!
It's sth wrong? Or maybe there is another way of reading database info?Thanks!

Shankar MPosted Apr 25, 2013, 1:40 AM
You can use the HasRows property of the reader object to check that rows are returns by the ExecuteReader() Method and
while(reader.Reader())
{
MessageBox.Show (reader["ENAME"].ToString());
}
To Loop through the data.
Jignesh TrivediPosted Apr 17, 2013, 12:18 AM
try
string selectDauna = "SELECT nr_dauna FROM dauna WHERE id_client='" + 16 + "'";
SqlCommand executaSelectDauna = new SqlCommand(selectDauna, conn);
conn.Open();
SqlDataReader rdr_dauna = executaSelectDauna.ExecuteReader();
if (rdr_dauna.HasRows == true)
{
while (rdr_dauna.Read())
{
nr_dauna = Convert.ToInt32(rdr_dauna.GetInt32(0));
}
}
rdr_dauna.Close();
it might work for you.
Javeed M ShaikhPosted Apr 16, 2013, 4:50 PM
Violeta PopaPosted Apr 16, 2013, 4:29 PM
Javeed M ShaikhPosted Apr 16, 2013, 4:12 PM
try the following command before you give rdr_dauna.Read(); and see if this is true
rdr_dauna.HasRows