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. C# SQL data check like in PHP???

C# SQL data check like in PHP???

Scheduled Pinned Locked Moved C#
databasecsharpphpsecurityhelp
5 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.
  • C Offline
    C Offline
    cemlouis
    wrote on last edited by
    #1

    Hi, I have a problem, I want to check a data is entered to SQL database or not. I am making this in PHP like below: $sql_name_check = mysql_query("SELECT name FROM names WHERE name='$buffer_name'"); if(!mysql_num_rows($sql_name_check)){ //Do this do that... } So I want to do that in C# so I made a code block which is below: int k=0; string buffer_name = "Cem Louis"; SqlConnection mySqlConnection = new SqlConnection("Initial Catalog=names;Data Source=localhost;Integrated Security=SSPI;"); SqlCommand mySqlCommand = mySqlConnection.CreateCommand(); mySqlCommand.CommandText = "SELECT name, tel FROM names WHERE tel = '1' AND name = name"; mySqlConnection.Open(); SqlDataReader mySqlDataReader3 = mySqlCommand.ExecuteReader(); while(mySqlDataReader3.Read()) { k++; } if(k > 0) //Do this do that... return false; else return true; mySqlDataReader3.Close(); mySqlConnection.Close(); Thank you; Cem Louis...

    W 1 Reply Last reply
    0
    • C cemlouis

      Hi, I have a problem, I want to check a data is entered to SQL database or not. I am making this in PHP like below: $sql_name_check = mysql_query("SELECT name FROM names WHERE name='$buffer_name'"); if(!mysql_num_rows($sql_name_check)){ //Do this do that... } So I want to do that in C# so I made a code block which is below: int k=0; string buffer_name = "Cem Louis"; SqlConnection mySqlConnection = new SqlConnection("Initial Catalog=names;Data Source=localhost;Integrated Security=SSPI;"); SqlCommand mySqlCommand = mySqlConnection.CreateCommand(); mySqlCommand.CommandText = "SELECT name, tel FROM names WHERE tel = '1' AND name = name"; mySqlConnection.Open(); SqlDataReader mySqlDataReader3 = mySqlCommand.ExecuteReader(); while(mySqlDataReader3.Read()) { k++; } if(k > 0) //Do this do that... return false; else return true; mySqlDataReader3.Close(); mySqlConnection.Close(); Thank you; Cem Louis...

      W Offline
      W Offline
      Werdna
      wrote on last edited by
      #2

      And your question is?

      C 1 Reply Last reply
      0
      • W Werdna

        And your question is?

        C Offline
        C Offline
        cemlouis
        wrote on last edited by
        #3

        :) And my question is: How can I know that the SQL query returns a result? Is the cell filled with data??? The C# code that I wrote above is not doing this with variable k++ increment... Thanks...

        W 1 Reply Last reply
        0
        • C cemlouis

          :) And my question is: How can I know that the SQL query returns a result? Is the cell filled with data??? The C# code that I wrote above is not doing this with variable k++ increment... Thanks...

          W Offline
          W Offline
          Werdna
          wrote on last edited by
          #4

          If you have any rows returned SqlDataReader has property HasRows SO you can do: if (reader.HasRows) { // something returned }

          C 1 Reply Last reply
          0
          • W Werdna

            If you have any rows returned SqlDataReader has property HasRows SO you can do: if (reader.HasRows) { // something returned }

            C Offline
            C Offline
            cemlouis
            wrote on last edited by
            #5

            hmm HasRows... Thank you...

            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