Home
Manage Your Code
Snippet: Ent Lib SQL Con, Sproc, ExecuteReader (C#)
Title: Ent Lib SQL Con, Sproc, ExecuteReader Language: C#
Description: This C# code describes how to do a SQL connection using Enterprise Library executing a stored procedure that returns data to be read one by one. Views: 841
Author: Sam Dela Cruz Date Added: 12/7/2007
Copy Code  
1private string AdToolsConnection = ConfigurationManager.AppSettings["DatabaseMode"];
2
3try
4        {
5            Database db = DatabaseFactory.CreateDatabase(AdToolsConnection);
6            string sqlCommand = "GetEmailStatus";
7            DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
8            db.AddInParameter(dbCommand, "GroupName", DbType.String, group);
9            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
10            {
11                while (dataReader.Read())
12                {
13                    if (dataReader["EmailDate"] != null)
14                    {
15                        emailDate = dataReader["EmailDate"].ToString();
16                    }
17
18                    if (dataReader["ReplyDate"] != null)
19                    {
20                        responseDate = dataReader["ReplyDate"].ToString();
21                    }
22                }
23            }
24        }
25        catch (Exception)
26        {
27            throw;
28        }