Diff betn ExecuteNonQuery & ExecuteScalar
-
Hello Guys, Can anyone tell me the difference between ExecuteNonQuery & ExecuteScalar. Also, in what cases should one use ExecuteNonQuery & ExecuteScalar. With Best Regards, Mayur
-
Hello Guys, Can anyone tell me the difference between ExecuteNonQuery & ExecuteScalar. Also, in what cases should one use ExecuteNonQuery & ExecuteScalar. With Best Regards, Mayur
use ExecuteScaler when u need to get only one value from DB(i.e. when u're using aggregate func) and use ExecuteNonQuery when u need to insert/update/delete operation. e.g if ur query is "SELECT AVG(sal) FROM MyTable" then use ExecuteScaler, because it returns only one value. this is not the end, this is how its goin to begin !
-
use ExecuteScaler when u need to get only one value from DB(i.e. when u're using aggregate func) and use ExecuteNonQuery when u need to insert/update/delete operation. e.g if ur query is "SELECT AVG(sal) FROM MyTable" then use ExecuteScaler, because it returns only one value. this is not the end, this is how its goin to begin !
considering your eg. if i need to obtain the avg(sal) of emp from a table group by department, then will i get several records as per the departments if i use executescalar. thnx for your reply. With Best Regards, Mayur
-
considering your eg. if i need to obtain the avg(sal) of emp from a table group by department, then will i get several records as per the departments if i use executescalar. thnx for your reply. With Best Regards, Mayur
-
then u cant use ExecuteScaler in dat case. or u can use ExecuteScaler but it'll return the first value returned by SQL Query...its only for one value... this is not the end, this is how its goin to begin !
ok thnx a lot. also i noticed 'ExecuteReader'. Any idea about it. Also, i need to know whether there is any way where I insert/update/delete records to the datatable and reflect all changes to the database in the end. My current operation is taking a lot of time to execute each insert/update/delete statement. With Best Regards, Mayur -- modified at 4:17 Wednesday 22nd February, 2006
-
ok thnx a lot. also i noticed 'ExecuteReader'. Any idea about it. Also, i need to know whether there is any way where I insert/update/delete records to the datatable and reflect all changes to the database in the end. My current operation is taking a lot of time to execute each insert/update/delete statement. With Best Regards, Mayur -- modified at 4:17 Wednesday 22nd February, 2006
ExecuteReader used in simple database read operation to populate SQLDataReader with ur query...like // some code Dim dr As SQLDataReader=cmd.ExecuteReader while( dr.Read() ) // get values using dr.GetValue(0) End While as of ur 2nd question, i need chk out n will post here later, becoz i forgot the code ...all i can say is updation of DB from DataTable is ALWAYS possible. this is not the end, this is how its goin to begin !
-
ExecuteReader used in simple database read operation to populate SQLDataReader with ur query...like // some code Dim dr As SQLDataReader=cmd.ExecuteReader while( dr.Read() ) // get values using dr.GetValue(0) End While as of ur 2nd question, i need chk out n will post here later, becoz i forgot the code ...all i can say is updation of DB from DataTable is ALWAYS possible. this is not the end, this is how its goin to begin !
Thnx a lot. I will be waiting for your reply regarding 'Database updation from datatable". Right now I am facing a lot of problem using the traditional method of updating each record since the operation involves huge data. Once again thx for your help. Have a nice day. With Best Regards, Mayur