hi,
i want to count Attendancecolumn and display on textbox.i have the following code but it gives error.give me proper code as soon as possible.
public void countattedence()
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\SJPDbase.mdb");
con.Open();
OleDbCommand cmd = new OleDbCommand("select count(Attendance) from dbo_Attandances where Emp_Name='" + cmbName.SelectedItem + "'", con);
//SqlDataReader dr;
OleDbDataReader dr;
dr = cmd.ExecuteReader();
while(dr.Read())
{
//int c = Convert.ToInt32( dr["Attendance"]);
txtprd.Text = dr["Attendance"].ToString();
}
con.Close();
}
Loading

Abdullah Munshi51 reputationPosted Jan 19, 2012, 10:32 PM EST
Dhaval PatelRank #1,023 · 1.9K reputationPosted Jan 19, 2012, 10:50 PM EST
use your change code for count attandance
public void countattedence()
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\SJPDbase.mdb");
con.Open();
OleDbCommand cmd = new OleDbCommand("select count(Attendance) as Attendance from dbo_Attandances where Emp_Name='" + cmbName.SelectedItem + "'", con);
//SqlDataReader dr;
OleDbDataReader dr;
dr = cmd.ExecuteReader();
while(dr.Read())
{
//int c = Convert.ToInt32( dr["Attendance"]);
txtprd.Text = dr["Attendance"].ToString();
}
con.Close();
}
change sql query for given allias
but try to use executescalar for that because scalar is better than datareader for single value .
Thanks & regards
Dhaval Patel
This post help you than Mark As Accepted Answer
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 19, 2012, 11:34 PM EST
change your query to.
select count(Attendance) as Attendance from dbo_Attandances where Emp_Name='name'
and also,
if count is single column record then use executescalar method.
hope this help.