Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

What could be used in C# instead of Reader?

Posted on 2015-01-23
3
Medium Priority
?
86 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

Expert Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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