Writing SQL statement in C#
-
I am developing an application on Win mobile 5.0 emulator in C# using Visual studio 2008. Can anyone let me know how to write an SQL statement in C# which returns the row count? Is the parameter required to store the count value? I will be greatefull if someone helps with the code snippet for the same. I have tried the following code for the select statement(the select stmt does not return the row count value) and is working fine. String uname_in='abc'; SqlCeConnection conn; SqlCeCommand comm; SqlCeDataAdapter adap = new SqlCeDataAdapter(); String connstring = @"Data Source=Program Files\signup\signupdb.sdf"; conn = new SqlCeConnection(connstring); conn.Open(); comm = new SqlCeCommand(); comm.Connection = conn; comm.CommandText = "select * from signuptbl where username =@uname"; SqlCeParameter para = new SqlCeParameter(); para.ParameterName = "@uname"; para.Value = uname_in; comm.Parameters.Add(para); adap.SelectCommand = comm; System.Data.DataTable dt = new DataTable(); ap.Fill(dt); psw1 = dt.Rows[0][1].ToString(); What changes should be done in the above code for writing a select stmt the return the number of rows selected? thanks in advance :-D
-
I am developing an application on Win mobile 5.0 emulator in C# using Visual studio 2008. Can anyone let me know how to write an SQL statement in C# which returns the row count? Is the parameter required to store the count value? I will be greatefull if someone helps with the code snippet for the same. I have tried the following code for the select statement(the select stmt does not return the row count value) and is working fine. String uname_in='abc'; SqlCeConnection conn; SqlCeCommand comm; SqlCeDataAdapter adap = new SqlCeDataAdapter(); String connstring = @"Data Source=Program Files\signup\signupdb.sdf"; conn = new SqlCeConnection(connstring); conn.Open(); comm = new SqlCeCommand(); comm.Connection = conn; comm.CommandText = "select * from signuptbl where username =@uname"; SqlCeParameter para = new SqlCeParameter(); para.ParameterName = "@uname"; para.Value = uname_in; comm.Parameters.Add(para); adap.SelectCommand = comm; System.Data.DataTable dt = new DataTable(); ap.Fill(dt); psw1 = dt.Rows[0][1].ToString(); What changes should be done in the above code for writing a select stmt the return the number of rows selected? thanks in advance :-D
Deepali Khalkar wrote:
the select stmt does not return the row count value) and is working fine.
So, what you saying is the code works fine but your didn't get any rows returned
Deepali Khalkar wrote:
comm.CommandText = "select * from signuptbl where username =@uname"; What changes should be done in the above code for writing a select stmt the return the number of rows selected?
your select statement looks fine. And you mentioned it works. there is a condition on your statement
where username =@uname";
may be you don't have data that satisfied your condition.
Yusuf