Solved

What could be used in C# instead of Reader?

Posted on 2015-01-23
3
76 Views
Last Modified: 2015-01-23
I am new to C# and never worked with it before, but for some reason I must chose it for my SQL 2012 SSIS script task. I need to retrieve data from SQL Server database. But using Reader: reader = cmd.ExecuteReader(); my script throws an exception when Reader gets NULL value, e.g reader.GetString(x). Is there any better way to retrieve the data? And another question I am trying to assign the data to the String variable but it produce an extension. I declared it as String sStr; and using sStr = reader.GetString(x). What do I do wrong?
0
Comment
Question by:Burzhuin
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40566596
Hi Burzhuin;

The GetString method must return a non null value so you will need to test if it has a value first like in the following code snippet.

// Initialize the variable to an empty string
string sStr = "";
// Get the Field/Column only if not null 
if ( !reader.IsDBNull(x) )
   sStr = reader.GetString(x);

Open in new window


Not sure what you mean by this, "And another question I am trying to assign the data to the String variable but it produce an extension.", can you explain in a little more detail.
0
 

Author Closing Comment

by:Burzhuin
ID: 40566723
Thank you. It works. I do appreciate it.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40566826
Not a problem Burzhuin;, glad to help.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now