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 MunshiPosted Jan 20, 2012, 3:32 AM
Jignesh TrivediPosted Jan 20, 2012, 4:34 AM
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.
Dhaval PatelPosted Jan 20, 2012, 3:50 AM
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