• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 560
  • Last Modified:

asp.net c# sqldatareader compare value with String

Hi,

I have this code that gets the fields from the database

SqlCommand gories = new SqlCommand("sp_writs", oCottoNwsCateies);
       NewsCategories.CommandType = CommandType.StoredProcedure;

        SqlDataReader rdrNewsCategories = NewsCategories.ExecuteReader();

so this code is fine.

but I have a coloum in the database caled write which I want to compare to a string called dontwrite

so I want to do is
if write is"page" and page is not equal to dont write then insert otherwise ignore

please help

Thanks,

R8VI


0
R8VI
Asked:
R8VI
  • 2
1 Solution
 
Jammer59Commented:
See code snippet

while (rdrNewsCategories.Read())
{
     if ((dr["write"].ToString() == "page") && 
         (dr["page"].ToString () !   = "dontwrite"))
     {
         // perform your insert logic
     }
}

Open in new window

0
 
Jammer59Commented:
Somehow in my code snippet on line 4 what should be != has spaces in it.
0
 
MaxOvrdrv2Commented:
this could also be an SQL reserved word issue... in that case, try Jammer's option above, and use this:

dr["[write]"]

instead...

write could be an SQL transaction word like DROP or SELECT... so your field name may be in conflict in the SQL query, thus you,re getting nothing in that field?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now