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!


Javeed M ShaikhRank #839 · 2.7K reputationPosted Apr 16, 2013, 12:12 PM EDT
try the following command before you give rdr_dauna.Read(); and see if this is true
rdr_dauna.HasRows
Violeta Popa132 reputationPosted Apr 16, 2013, 12:29 PM EDT
Javeed M ShaikhRank #839 · 2.7K reputationPosted Apr 16, 2013, 12:50 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 16, 2013, 8:18 PM EDT
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.
Shankar MRank #874 · 2.5K reputationPosted Apr 24, 2013, 9:40 PM EDT
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.