compare value of variable with all values in a sql server08 table column using c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thomaaxha
    New Member
    • Mar 2013
    • 16

    compare value of variable with all values in a sql server08 table column using c#

    Hello , i want to compare a value of a variable with all the values in a table column c# and sql server08. if this value is in column do nothing , if it is in the column do sth .. please help me for my project!! what to use :/
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    thomaaxha,

    What have you done on this problem to help yourself?

    Obviously you will have to use SQL under C#, now what?

    Oralloy

    Comment

    • thomaaxha
      New Member
      • Mar 2013
      • 16

      #3
      ok i did it , but i have to find if a variable value exist in a table column or not

      Comment

      • vijay6
        New Member
        • Mar 2010
        • 158

        #4
        Hey thomaaxha, you can use SQL COUNT() Function. Like this,

        Code:
        SELECT COUNT[Column_name(s)] FROM [Table_name] WHERE [Condition]

        After this check count value, if it is > 0 then value already exists in table else not exists.

        Comment

        • thomaaxha
          New Member
          • Mar 2013
          • 16

          #5
          I am gonna try this ,, :) .. thnx

          Comment

          • thomaaxha
            New Member
            • Mar 2013
            • 16

            #6
            [Column_name(s)] --> what do you refer with (s)???

            Comment

            • thomaaxha
              New Member
              • Mar 2013
              • 16

              #7
              i have this problem:

              Code:
              string gjejip = "SELECT COUNT (*) FROM [Table_ip] WHERE [IP_votuesit = '" + ip + "']";
                              SqlCommand cmdFutIp = new SqlCommand(gjejip, con);
                              string gjejip1 = cmdFutIp.ExecuteScalar().ToString();
                              Label8.Text = gjejip1;

              the error is: An expression of non-boolean type specified in a context where a condition is expected, near 'IP_votuesit = '127.0.0.1''.
              Last edited by Rabbit; May 27 '13, 10:28 PM. Reason: Please use code tags when posting code.

              Comment

              • vijay6
                New Member
                • Mar 2010
                • 158

                #8
                [Column_name(s)] --> what do you refer with (s)???
                General syntax of select query.

                Hey thomaaxha, in your code remove those square brackets '[' and ']' (which you used for where condition) and try...

                Comment

                Working...