Click here to Skip to main content
15,887,967 members
Home / Discussions / C#
   

C#

 
AnswerRe: Boolean function to return true/false Pin
Matt T Heffron7-Jan-13 11:01
professionalMatt T Heffron7-Jan-13 11:01 
GeneralRe: Boolean function to return true/false Pin
Member 97041537-Jan-13 11:30
Member 97041537-Jan-13 11:30 
GeneralRe: Boolean function to return true/false Pin
Member 97041537-Jan-13 11:57
Member 97041537-Jan-13 11:57 
AnswerRe: Boolean function to return true/false Pin
Matt T Heffron7-Jan-13 12:03
professionalMatt T Heffron7-Jan-13 12:03 
GeneralRe: Boolean function to return true/false Pin
Member 97041537-Jan-13 12:12
Member 97041537-Jan-13 12:12 
AnswerRe: Boolean function to return true/false Pin
Matt T Heffron7-Jan-13 12:29
professionalMatt T Heffron7-Jan-13 12:29 
GeneralRe: Boolean function to return true/false Pin
Member 97041537-Jan-13 12:39
Member 97041537-Jan-13 12:39 
GeneralRe: Boolean function to return true/false Pin
Matt T Heffron7-Jan-13 11:57
professionalMatt T Heffron7-Jan-13 11:57 
I think I see the problem.
The code I gave was to check if any of Sheet1Name, Sheet2Name or Sheet3Name are in the DB. Are you trying to check if all of non-null values of Sheet1Name, Sheet2Name or Sheet3Name are represented as rows in the DB?
If that is the case, you will need more complicated checking and keeping track of matching each of the sheet names separately.
Try something like:

The code as you have shown it will throw a NullReferenceException if any of Sheet1Name, Sheet2Name or Sheet3Name are null. You can use the ?? operator to make this safe:
C#
// Initialize these so null Sheet?Names pass the checking
bool Exists1 = Sheet1Name == null;
bool Exists2 = Sheet2Name == null;
bool Exists3 = Sheet3Name == null;
string Sheet1NameSuffix = (Sheet1Name ?? "") + "$";
string Sheet2NameSuffix = (Sheet2Name ?? "") + "$";
string Sheet3NameSuffix = (Sheet3Name ?? "") + "$";
foreach (DataRow row in dt.Rows)
{
    string tableName = row["TABLE_NAME"].ToString();
    if (tableName == Sheet1NameSuffix)
    {
        Exists1 = true;
    }
    if (tableName == Sheet2NameSuffix)
    {
        Exists2 = true;
    }
    if (tableName == Sheet3NameSuffix)
    {
        Exists3 = true;
    }
}
if (Exists1 && Exists2 && Exists3)
{
    MessageBox.Show("Match");
}
else
    MessageBox.Show("No Match");

GeneralRe: Boolean function to return true/false Pin
Member 97041537-Jan-13 12:02
Member 97041537-Jan-13 12:02 
QuestionC# data tranfer to form in textbox Pin
Member 970663330-Dec-12 2:44
Member 970663330-Dec-12 2:44 
AnswerRe: C# data tranfer to form in textbox Pin
Richard MacCutchan30-Dec-12 4:29
mveRichard MacCutchan30-Dec-12 4:29 
GeneralRe: C# data tranfer to form in textbox Pin
Member 970663330-Dec-12 8:07
Member 970663330-Dec-12 8:07 
GeneralRe: C# data tranfer to form in textbox Pin
Richard MacCutchan30-Dec-12 22:10
mveRichard MacCutchan30-Dec-12 22:10 
AnswerRe: C# data tranfer to form in textbox Pin
BillWoodruff3-Jan-13 17:37
professionalBillWoodruff3-Jan-13 17:37 
QuestionHow to solve the following problem using StreamReader. Pin
dr_iton30-Dec-12 0:20
dr_iton30-Dec-12 0:20 
AnswerRe: How to solve the following problem using StreamReader. Pin
Jibesh30-Dec-12 1:19
professionalJibesh30-Dec-12 1:19 
AnswerRe: How to solve the following problem using StreamReader. Pin
Richard MacCutchan30-Dec-12 2:37
mveRichard MacCutchan30-Dec-12 2:37 
GeneralRe: How to solve the following problem using StreamReader. Pin
dr_iton31-Dec-12 14:38
dr_iton31-Dec-12 14:38 
GeneralRe: How to solve the following problem using StreamReader. Pin
Richard MacCutchan31-Dec-12 22:36
mveRichard MacCutchan31-Dec-12 22:36 
GeneralRe: How to solve the following problem using StreamReader. Pin
dr_iton1-Jan-13 8:58
dr_iton1-Jan-13 8:58 
GeneralRe: How to solve the following problem using StreamReader. Pin
Richard MacCutchan1-Jan-13 22:11
mveRichard MacCutchan1-Jan-13 22:11 
GeneralRe: How to solve the following problem using StreamReader. Pin
dr_iton4-Jan-13 10:17
dr_iton4-Jan-13 10:17 
GeneralRe: How to solve the following problem using StreamReader. Pin
Richard MacCutchan5-Jan-13 1:18
mveRichard MacCutchan5-Jan-13 1:18 
GeneralRe: How to solve the following problem using StreamReader. Pin
dr_iton5-Jan-13 2:58
dr_iton5-Jan-13 2:58 
GeneralRe: How to solve the following problem using StreamReader. Pin
Richard MacCutchan5-Jan-13 3:04
mveRichard MacCutchan5-Jan-13 3:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.