[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

asp.net c# sqldatareader compare value with String

Posted on 2009-02-13
3
Medium Priority
?
553 Views
Last Modified: 2013-12-17
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
Comment
Question by:R8VI
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
Jammer59 earned 2000 total points
ID: 23632299
See code snippet

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

Open in new window

0
 
LVL 6

Expert Comment

by:Jammer59
ID: 23632302
Somehow in my code snippet on line 4 what should be != has spaces in it.
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 23634051
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month17 days, 22 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question