By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,948 Members | 1,104 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,948 IT Pros & Developers. It's quick & easy.

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

P: 16
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 :/
May 26 '13 #1
Share this Question
Share on Google+
7 Replies

Expert 100+
P: 983

What have you done on this problem to help yourself?

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

May 26 '13 #2

P: 16
ok i did it , but i have to find if a variable value exist in a table column or not
May 26 '13 #3

P: 158
Hey thomaaxha, you can use SQL COUNT() Function. Like this,

Expand|Select|Wrap|Line Numbers
  1. 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.
May 27 '13 #4

P: 16
I am gonna try this ,, :) .. thnx
May 27 '13 #5

P: 16
[Column_name(s)] --> what do you refer with (s)???
May 27 '13 #6

P: 16
i have this problem:

Expand|Select|Wrap|Line Numbers
  1. string gjejip = "SELECT COUNT (*) FROM [Table_ip] WHERE [IP_votuesit = '" + ip + "']";
  2.                 SqlCommand cmdFutIp = new SqlCommand(gjejip, con);
  3.                 string gjejip1 = cmdFutIp.ExecuteScalar().ToString();
  4.                 Label8.Text = gjejip1;

the error is: An expression of non-boolean type specified in a context where a condition is expected, near 'IP_votuesit = '''.
May 27 '13 #7

P: 158
[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...
May 28 '13 #8

Post your reply

Sign in to post your reply or Sign up for a free account.