Click here to Skip to main content
15,910,878 members
Home / Discussions / C#
   

C#

 
QuestionPlease help - How to un-install a Windows Service? Pin
Tigger9925-Oct-05 23:53
Tigger9925-Oct-05 23:53 
AnswerRe: Please help - How to un-install a Windows Service? Pin
seee sharp26-Oct-05 0:15
seee sharp26-Oct-05 0:15 
Questionhow do you create a dbf file? Pin
Anonymous25-Oct-05 23:09
Anonymous25-Oct-05 23:09 
QuestionList box Pin
User 58385225-Oct-05 20:24
User 58385225-Oct-05 20:24 
AnswerRe: List box Pin
User 58385225-Oct-05 20:34
User 58385225-Oct-05 20:34 
GeneralRe: List box Pin
technomanceraus25-Oct-05 21:08
technomanceraus25-Oct-05 21:08 
GeneralRe: List box Pin
User 58385225-Oct-05 21:14
User 58385225-Oct-05 21:14 
QuestionDataReader Pin
Brendan Vogt25-Oct-05 20:16
Brendan Vogt25-Oct-05 20:16 
Hi!!

I have a call to my data access class and I do it like this (from my displayNews.aspx page:

News objNews = NewsDA.GetNewsDetails(m_iNewsID);

m_iNewsID is the id number which I got from the query string

And my GetNewsDetails in my NewsDA class looks like this:

public static News GetNewsDetails(int intNewsID)
{
News objNews = new News();

// Create instance of connection and command object
SqlConnection objConn = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand objCmd = new SqlCommand("sp_GetNewsByID", objConn);

// Mark the command as a SPROC
objCmd.CommandType = CommandType.StoredProcedure;

// Add parameters to SPROC
SqlParameter paramNewsID = new SqlParameter("@NewsID", SqlDbType.Int, 4);
paramNewsID.Value = intNewsID;
objCmd.Parameters.Add(paramNewsID);

// Execute the statement
try
{
objConn.Open();
SqlDataReader objDr = objCmd.ExecuteReader();

try
{
while (objDr.Read())
{
objNews.NewsID = Convert.ToInt32(objDr["PKNewsID"]);
objNews.CategoryID = Globals.CheckDBIntForDBNulls(objDr["FKNewsCategoryID"]);
objNews.Title = objDr["NewsTitle"].ToString();
}
}
finally
{
if(!objDr.IsClosed)
{
objDr.Close();
}
}
}
finally
{
if(objConn.State == ConnectionState.Open)
{
objConn.Close();
}
objConn.Dispose();
objCmd.Dispose();
}

// Return the news object
return objNews;
}

If no records are found, then I should probably set objNews to null?? And the where I call this function, then I should probably test if the news object is equal to null?? I was thinking of putting in an if statement there in the second try block, if the dataset has rows, then do the while statement, otherwise set the objNews = null??

Please can some one advise. If there is a better way of testing if an object of News has any records (rows) in it, please let me know.

Regards,
ma se
AnswerRe: DataReader Pin
leppie25-Oct-05 22:03
leppie25-Oct-05 22:03 
QuestionRe: DataReader Pin
Brendan Vogt25-Oct-05 22:33
Brendan Vogt25-Oct-05 22:33 
AnswerRe: DataReader Pin
Colin Angus Mackay25-Oct-05 22:42
Colin Angus Mackay25-Oct-05 22:42 
QuestionEditing Pin
momoo25-Oct-05 19:45
momoo25-Oct-05 19:45 
AnswerRe: Editing Pin
Christian Graus25-Oct-05 20:07
protectorChristian Graus25-Oct-05 20:07 
QuestionCollections Pin
seee sharp25-Oct-05 19:05
seee sharp25-Oct-05 19:05 
AnswerRe: Collections Pin
Christian Graus25-Oct-05 19:23
protectorChristian Graus25-Oct-05 19:23 
GeneralRe: Collections Pin
seee sharp25-Oct-05 21:06
seee sharp25-Oct-05 21:06 
GeneralRe: Collections Pin
Christian Graus26-Oct-05 10:20
protectorChristian Graus26-Oct-05 10:20 
AnswerRe: Collections Pin
S. Senthil Kumar25-Oct-05 22:32
S. Senthil Kumar25-Oct-05 22:32 
QuestionView Source Code Pin
alok_2k325-Oct-05 18:55
alok_2k325-Oct-05 18:55 
AnswerRe: View Source Code Pin
seee sharp25-Oct-05 19:08
seee sharp25-Oct-05 19:08 
Questioninherited controls Pin
xilefxilef25-Oct-05 18:19
xilefxilef25-Oct-05 18:19 
AnswerRe: inherited controls Pin
Longxe25-Oct-05 18:24
Longxe25-Oct-05 18:24 
Questiondraw above a control? Pin
Longxe25-Oct-05 17:37
Longxe25-Oct-05 17:37 
AnswerRe: draw above a control? Pin
Christian Graus25-Oct-05 17:49
protectorChristian Graus25-Oct-05 17:49 
GeneralRe: draw above a control? Pin
Longxe25-Oct-05 18:07
Longxe25-Oct-05 18:07 

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.