Click here to Skip to main content
15,893,487 members
Home / Discussions / Database
   

Database

 
GeneralRe: Can i include a procedure inside a triger???? Pin
Vimalsoft(Pty) Ltd12-Apr-07 3:16
professionalVimalsoft(Pty) Ltd12-Apr-07 3:16 
QuestionDeallocating variable in SQL Server Pin
rachitdamani10-Apr-07 20:34
rachitdamani10-Apr-07 20:34 
AnswerRe: Deallocating variable in SQL Server Pin
Colin Angus Mackay10-Apr-07 20:41
Colin Angus Mackay10-Apr-07 20:41 
AnswerRe: Deallocating variable in SQL Server Pin
Jaiprakash M Bankolli10-Apr-07 20:57
Jaiprakash M Bankolli10-Apr-07 20:57 
AnswerRe: Deallocating variable in SQL Server Pin
N a v a n e e t h10-Apr-07 22:32
N a v a n e e t h10-Apr-07 22:32 
QuestionNotification when a new column is added to a table Pin
deepakts10-Apr-07 19:17
deepakts10-Apr-07 19:17 
AnswerRe: Notification when a new column is added to a table Pin
Jaiprakash M Bankolli10-Apr-07 20:58
Jaiprakash M Bankolli10-Apr-07 20:58 
QuestionTry/Catch with data acess Pin
Quinten.Miller10-Apr-07 18:47
Quinten.Miller10-Apr-07 18:47 
Howdy All

I'm new to C#, recently converted from Java. I'm still learning the coding differences.

One that I have seen around a fair bit is data access code. Below is a code fragment for accessing a database. Normally (in Java) I would use try/catch/finally for surround the connection etc. In C# the using statement works well for cleaning up the connection (if I understand it correctly). In bold I have added code that handles and logs the exception then throws it up to the next tier. I don't see many (or any) examples with a try catch block inside a using statement (the bold code). Is there reason for this?

Any advice for writing DAL code (not using datasets)

public static bool Delete(int supplierID)
{
    int result = 0;
    using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
    {
        SqlCommand myCommand = new SqlCommand("sprocProcSupplierDelete", myConnection);
        myCommand.CommandType = CommandType.StoredProcedure;
        myCommand.Parameters.Add(Parameters.SupplierID);
        myCommand.Parameters[ParameterNames.SupplierID].Value = supplierID;
        try
        {
            myConnection.Open();
            result = myCommand.ExecuteNonQuery();
            myConnection.Close();
        }
        catch (SQLException e)
        {
            // handle exception
            ...
            // log exception
            ...
            throw;
        }
    }
    return result > 0;
}


Thanks heaps for any help
AnswerRe: Try/Catch with data acess Pin
Colin Angus Mackay10-Apr-07 20:38
Colin Angus Mackay10-Apr-07 20:38 
AnswerRe: Try/Catch with data acess Pin
Svett11-Apr-07 10:54
Svett11-Apr-07 10:54 
QuestionData Access Layer on Web Service Pin
Tuwing.Sabado10-Apr-07 16:36
Tuwing.Sabado10-Apr-07 16:36 
AnswerRe: Data Access Layer on Web Service Pin
Colin Angus Mackay10-Apr-07 20:45
Colin Angus Mackay10-Apr-07 20:45 
QuestionCan we add SQL Server 2000 backup to SQL Server 2005 Database? Pin
pubududilena10-Apr-07 3:44
pubududilena10-Apr-07 3:44 
AnswerRe: Can we add SQL Server 2000 backup to SQL Server 2005 Database? Pin
Krish - KP10-Apr-07 20:45
Krish - KP10-Apr-07 20:45 
GeneralRe: Can we add SQL Server 2000 backup to SQL Server 2005 Database? Pin
Marek Grzenkowicz11-Apr-07 0:38
Marek Grzenkowicz11-Apr-07 0:38 
GeneralRe: Can we add SQL Server 2000 backup to SQL Server 2005 Database? Pin
Krish - KP11-Apr-07 1:10
Krish - KP11-Apr-07 1:10 
Questionmusic play Pin
pratima19-Apr-07 22:46
pratima19-Apr-07 22:46 
AnswerRe: music play Pin
_mubashir9-Apr-07 23:08
_mubashir9-Apr-07 23:08 
AnswerRe: music play Pin
Colin Angus Mackay9-Apr-07 23:26
Colin Angus Mackay9-Apr-07 23:26 
AnswerRe: music play Pin
Paddy Boyd10-Apr-07 5:38
Paddy Boyd10-Apr-07 5:38 
Questionhow to put date from 2nd table to 1st table. Pin
honda15i9-Apr-07 22:21
honda15i9-Apr-07 22:21 
AnswerRe: how to put date from 2nd table to 1st table. Pin
_mubashir9-Apr-07 22:46
_mubashir9-Apr-07 22:46 
AnswerRe: how to put date from 2nd table to 1st table. Pin
Krish - KP10-Apr-07 2:11
Krish - KP10-Apr-07 2:11 
QuestionError! Pin
nclauder9-Apr-07 21:27
nclauder9-Apr-07 21:27 
AnswerRe: Error! Pin
_mubashir9-Apr-07 23:10
_mubashir9-Apr-07 23:10 

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.