Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Writing SQL statement in C#

Writing SQL statement in C#

Scheduled Pinned Locked Moved C#
csharpdatabasevisual-studiotutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Deepali Khalkar
    wrote on last edited by
    #1

    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

    Y 1 Reply Last reply
    0
    • D Deepali Khalkar

      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

      Y Offline
      Y Offline
      Yusuf
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups