Return a row count
-
I am trying to return Count(*), cast to a String and assign the value to Label1.Text. I am a bit stuck on the C# syntax because I am new to C#. This is what my research has produced thus far: protected void Button1_Click(object sender, EventArgs e) { using (SqlConnection conn = new SqlConnection(ConnString)) { //String newTagName = txtParm.Text; int DOWcount = 0; SqlCommand cmd = new SqlCommand("SELECT count(*)FROM RealTime WHERE DATEPART (d,CallStartTime) = DATEPART(d,getdate())", conn); cmd.Parameters.Count; conn.Open(); DOWcount = cmd.ExecuteNonQuery(); Label1.Text = DOWCount.ToString(); I know that I am not using the "cmd" correctly. Can anyone of the experts out there steer me in the right direction?
-
I am trying to return Count(*), cast to a String and assign the value to Label1.Text. I am a bit stuck on the C# syntax because I am new to C#. This is what my research has produced thus far: protected void Button1_Click(object sender, EventArgs e) { using (SqlConnection conn = new SqlConnection(ConnString)) { //String newTagName = txtParm.Text; int DOWcount = 0; SqlCommand cmd = new SqlCommand("SELECT count(*)FROM RealTime WHERE DATEPART (d,CallStartTime) = DATEPART(d,getdate())", conn); cmd.Parameters.Count; conn.Open(); DOWcount = cmd.ExecuteNonQuery(); Label1.Text = DOWCount.ToString(); I know that I am not using the "cmd" correctly. Can anyone of the experts out there steer me in the right direction?
mreynol5 wrote:
Can anyone of the experts out there steer me in the right direction?
No. No one knows how to do that. And if anyone did it certainly would not be Microsoft and they certainly would not document it.[^] And you certainly would not be able to find the documentation using Google[^]
mreynol5 wrote:
I am a bit stuck on the C# syntax because I am new to C#.
Ok, good luck
led mike
-
I am trying to return Count(*), cast to a String and assign the value to Label1.Text. I am a bit stuck on the C# syntax because I am new to C#. This is what my research has produced thus far: protected void Button1_Click(object sender, EventArgs e) { using (SqlConnection conn = new SqlConnection(ConnString)) { //String newTagName = txtParm.Text; int DOWcount = 0; SqlCommand cmd = new SqlCommand("SELECT count(*)FROM RealTime WHERE DATEPART (d,CallStartTime) = DATEPART(d,getdate())", conn); cmd.Parameters.Count; conn.Open(); DOWcount = cmd.ExecuteNonQuery(); Label1.Text = DOWCount.ToString(); I know that I am not using the "cmd" correctly. Can anyone of the experts out there steer me in the right direction?
Change this:
DOWcount = cmd.ExecuteNonQuery();
to this:DOWcount = (int)cmd.ExecuteScalar();
Hope that helps :)Sunrise Wallpaper Project | The StartPage Randomizer | The Windows Cheerleader