当前位置: 首页>>代码示例>>C#>>正文


C# System.Data.SqlClient.SqlCommand.ExecuteReader方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlCommand.ExecuteReader方法的典型用法代码示例。如果您正苦于以下问题:C# System.Data.SqlClient.SqlCommand.ExecuteReader方法的具体用法?C# System.Data.SqlClient.SqlCommand.ExecuteReader怎么用?C# System.Data.SqlClient.SqlCommand.ExecuteReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlCommand的用法示例。


在下文中一共展示了System.Data.SqlClient.SqlCommand.ExecuteReader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitClass

 private void InitClass(string name, int id = 0)
 {
     if (id != 0) this.id = id;
     if (!string.IsNullOrEmpty(name)) this.Name = name;
     using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[Configuration.ConnectionStringName].ConnectionString))
     {
         using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT * FROM Authorization_ActionGroups WHERE [email protected] OR [email protected]", conn))
         {
             try
             {
                 conn.Open();
                 if (!string.IsNullOrEmpty(name) && id == 0) cmd.CommandText = "SELECT * FROM Authorization_ActionGroups WHERE [email protected]";
                 cmd.Parameters.AddWithValue("@id", this.id);
                 cmd.Parameters.AddWithValue("@groupName", this.Name == null ? "" : this.Name);
                 System.Data.SqlClient.SqlDataReader reader = cmd.ExecuteReader();
                 while (reader.Read())
                 {
                     this.id = reader.GetInt32(0);
                     if (string.IsNullOrEmpty(this.Name)) this.Name = reader.GetString(1);
                     this.Active = reader.GetBoolean(2);
                 }
                 reader.Close();
                 cmd.CommandText = "SELECT * FROM Authorization_RoleToActionGroup WHERE [email protected]";
                 cmd.Parameters.Clear();
                 cmd.Parameters.AddWithValue("@groupID", this.id);
                 reader = cmd.ExecuteReader();
                 List<SystemRole> rolesList = new List<SystemRole>();
                 while (reader.Read())
                     rolesList.Add(new SystemRole(this.id, reader.GetString(2)));
                 this.Roles = rolesList.ToArray();
                 reader.Close();
                 cmd.Parameters.Clear();
                 cmd.Parameters.AddWithValue("@id", this.id);
                 List<Action> actionsList = new List<Action>();
                 cmd.CommandText = "SELECT ActionID FROM Authorization_ActionToGroup WHERE [email protected]";
                 reader = cmd.ExecuteReader();
                 while (reader.Read())
                 {
                     actionsList.Add(new Action(reader.GetInt32(0)));
                 }
                 this.GroupActions = actionsList.Distinct().ToArray();
             }
             catch (Exception ex)
             {
                 if (Configuration.s_log != null)
                     Configuration.s_log.Error("[Ошибка модуля авторизации] [Инициализация класса действия] ", ex);
             }
         }
     }
 }
开发者ID:EkzoMan,项目名称:Ekzo.Security,代码行数:50,代码来源:Ekzo.Web.Security.Utilization.Authorization.ActionGroup.cs

示例2: GetGroupUsers

        public static string[] GetGroupUsers(string intranetGroup)
        {
            List<string> result = new List<string>();
            try
            {
                
                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
                {
                    using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(@"SELECT employee.employee_name FROM groups INNER JOIN employee2group ON 
                                                                                                        groups.group_id=employee2group.group_id INNER JOIN
                                                                                                        employee ON employee2group.employee_id=employee.employee_id
                                                                                                        WHERE [email protected] ORDER BY employee.employee_name", conn))
                    {
                        try
                        {
                            conn.Open();
                            cmd.Parameters.AddWithValue("@name",intranetGroup);
                            System.Data.SqlClient.SqlDataReader reader = cmd.ExecuteReader();
                            while(reader.Read())
                                result.Add(reader.GetString(0));
                        }
                        catch (Exception ex)
                        {

                        }
                    }
                }
                return result.ToArray();
            }
            catch (Exception ex)
            {
                AuthLib.Core.Logging.WriteEntry("Ошибка получения списка пользователей в роли.",ex);
                throw new Exception("Ошибка получения списка пользователей в роли.", ex);
            }
        }
开发者ID:EkzoMan,项目名称:Ekzo.Security,代码行数:35,代码来源:AuthLib.Helpers.RoleProviderHelper.cs

示例3: RunTrace

        public Patware.PingTrace.Core.TraceResult RunTrace(string destination)
        {
            var ret = new Patware.PingTrace.Core.TraceResult();

            var connext = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["Database1"].ConnectionString);

            var cmd = new System.Data.SqlClient.SqlCommand("[PingTrace].[spTrace]", connext);
            cmd.Parameters.AddWithValue("@destination", destination);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            connext.Open();
            var res = cmd.ExecuteReader();

            if (res.Read())
            {

                ret.Id = res.GetGuid(0);
                ret.Name = res.GetString(1);
                ret.Identity = res.GetString(2);
                ret.MachineName = res.GetString(3);

                ret.Finish(res.GetString(4));

                return ret;
            }

            return null;
        }
开发者ID:patware,项目名称:PingTrace,代码行数:27,代码来源:Repository.cs

示例4: RunTraces

        public IList<Patware.PingTrace.Core.TraceDestination> RunTraces()
        {
            var connext = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["Database1"].ConnectionString);

            var cmd = new System.Data.SqlClient.SqlCommand("[PingTrace].[spTraces]", connext);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            connext.Open();
            var res = cmd.ExecuteReader();

            var l = new List<Patware.PingTrace.Core.TraceDestination>();

            while (res.Read())
            {
                /*
                 * 0                                    1           2                   3                   4                   5                       6                   7
                 * Id	                                Name	    ExpectedIdentity	ExpectedMachineName	ElapsedMaxSeconds	ElapsedAverageSeconds	PayloadDescription	PayloadRegex
                 * 188712E4-4E7E-417E-8C91-D9115BC0BE22	Database1	NULL	            SIAD049W\SQLEXPRESS	1	                1	                    Pong	            Pong
                 *
                 */
                var td = new Patware.PingTrace.Core.TraceDestination();
                td.Id = res.GetGuid(0);
                td.Name = res.GetString(1);
                td.ExpectedIdentity = res.IsDBNull(2) ? string.Empty : res.GetString(2);
                td.ExpectedMachineNames = new[] { res.GetString(3) };
                td.ExpectedElapsedMilisecondsMax = res.GetInt32(4);
                td.ExpectedElapsedMilisecondsAverage = res.GetInt32(5);
                td.PayloadDescription = res.GetString(6);
                td.PayloadRegex = res.GetString(7);

                l.Add(td);
            }

            return l;
        }
开发者ID:patware,项目名称:PingTrace,代码行数:34,代码来源:Repository.cs

示例5: obtenerGrupo

        public static blc.Grupo obtenerGrupo(string nombreGrupo, string codigoGrupo)
        {
            blc.Grupo grupo = new blc.Grupo();
            System.Data.SqlClient.SqlCommand Comando;
            System.Data.SqlClient.SqlDataReader DataReader;
            string query = "SELECT * FROM Grupo WHERE Nombre = '" + nombreGrupo + "' OR Codigo = '" + codigoGrupo + "'";

            Comando = new System.Data.SqlClient.SqlCommand(query);
            Comando.Connection = Program.dt.Connecion;
            Comando.Connection.Open();
            DataReader = Comando.ExecuteReader();

            while (DataReader.Read())
            {
                grupo.Codigo = (int)DataReader.GetValue(0);
                grupo.Nombre = DataReader.GetValue(1).ToString();
                grupo.PermisoGestion = DataReader.GetValue(2).ToString();
                grupo.PermisoCasos = DataReader.GetValue(3).ToString();
                grupo.PermisoClientes = DataReader.GetValue(4).ToString();
                grupo.PermisoTestigos = DataReader.GetValue(5).ToString();
                grupo.PermisoInventario = DataReader.GetValue(6).ToString();
                grupo.PermisoEvidencia = DataReader.GetValue(7).ToString();
                grupo.PermisoReportes = DataReader.GetValue(8).ToString();
                grupo.PermisoConfiguracion = DataReader.GetValue(9).ToString();
            }

            DataReader.Close();
            Comando.Connection.Close();
            return grupo;
        }
开发者ID:BigChief45,项目名称:LawHelper,代码行数:30,代码来源:ccGrupo.cs

示例6: existeEvidencia

        public static bool existeEvidencia(string codigo)
        {
            blc.Evidencia evidencia = new blc.Evidencia();
            System.Data.SqlClient.SqlCommand Comando;
            System.Data.SqlClient.SqlDataReader DataReader;
            string query = "SELECT * FROM Evidencia WHERE codigoEvidencia = '" + codigo + "'";

            Comando = new System.Data.SqlClient.SqlCommand(query);
            Comando.Connection = Program.dt.Connecion;
            Comando.Connection.Open();
            DataReader = Comando.ExecuteReader();

            if (DataReader.HasRows == true)
            {
                DataReader.Close();
                Comando.Connection.Close();
                return true;
            }
            else
            {
                DataReader.Close();
                Comando.Connection.Close();
                return false;
            }
        }
开发者ID:BigChief45,项目名称:LawHelper,代码行数:25,代码来源:ccEvidencia.cs

示例7: PopulateEmployerGroupDDL

        public void PopulateEmployerGroupDDL()
        {
            dbProcedures db = new dbProcedures();

            try
            {
                System.Data.SqlClient.SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand("SELECT DISTINCT EmployerGroup FROM tbl_Members ORDER BY EmployerGroup", new db().SqlConnection);
                sqlCmd.CommandType = System.Data.CommandType.Text;

                System.Data.DataTable loadReaderdata = new System.Data.DataTable();
                loadReaderdata.Load(sqlCmd.ExecuteReader());

                ddlEmployerGroup.DataSource = loadReaderdata;
                ddlEmployerGroup.DataTextField = "EmployerGroup";
                ddlEmployerGroup.DataValueField = "EmployerGroup";
                ddlEmployerGroup.DataBind();

                ddlEmployerGroup.Items.Insert(0, new ListItem("", ""));
                ddlEmployerGroup.SelectedIndex = 0;

            }
            catch (Exception ex)
            {
                db.LogAction("", "Error", "Error loading Members UI page. " + ex.Message.ToString());
            }

            db.Close();
        }
开发者ID:reagan83,项目名称:EOBSystemAdmin,代码行数:28,代码来源:Members.aspx.cs

示例8: buscarTestigo

        public static blc.Persona buscarTestigo(string id)
        {
            blc.Persona testigo = new blc.Persona();
            System.Data.SqlClient.SqlCommand Comando;
            System.Data.SqlClient.SqlDataReader DataReader;
            string query = "SELECT * FROM Testigo WHERE ID = '" + id + "'";

            Comando = new System.Data.SqlClient.SqlCommand(query);
            Comando.Connection = Program.dt.Connecion;
            Comando.Connection.Open();
            DataReader = Comando.ExecuteReader();

            while (DataReader.Read())
            {
                testigo.ID = DataReader.GetValue(0).ToString();
                testigo.Nombre = DataReader.GetValue(1).ToString();
                testigo.Apellido = DataReader.GetValue(2).ToString();
                testigo.Nacionalidad = DataReader.GetValue(4).ToString();
                testigo.Edad = (int)DataReader.GetValue(5);
                testigo.EstadoCivil = DataReader.GetValue(6).ToString();
                testigo.Domicilio = DataReader.GetValue(7).ToString();
                testigo.Telefono = DataReader.GetValue(8).ToString();
                testigo.Celular = DataReader.GetValue(9).ToString();
                testigo.Email = DataReader.GetValue(10).ToString();
                testigo.Foto = DataReader.GetValue(11).ToString();
            }
            DataReader.Close();
            Comando.Connection.Close();
            return testigo;
        }
开发者ID:BigChief45,项目名称:LawHelper,代码行数:30,代码来源:ccTestigo.cs

示例9: fnActivitySelect

        protected String fnActivitySelect(String strID)
        {
            String strTableBuild = "";
            System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SQLSERVER_CONNECTION_STRING"].ToString());
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            System.Data.SqlClient.SqlDataReader dr;

            cmd.CommandText = "SELECT tblActivity.intActivityType, tblActivity.txtNote FROM tblActivity INNER JOIN tblContacts ON tblActivity.intContactId = tblContacts.id WHERE (tblContacts.sfid = '" + strID + "')";

            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Connection = sqlConn;

            sqlConn.Open();

            dr = cmd.ExecuteReader();

            strTableBuild = strTableBuild + ("<div style=\"position:absolute; left: 400px; top: 275px;\">");
            strTableBuild = strTableBuild + ("<table border=1 bgcolor=silver style=\"border-collapse:collapse;\">");
            strTableBuild = strTableBuild + ("<th>Activity Type</th><th>Note</th>");
            while (dr.Read())
            {
                strTableBuild = strTableBuild + "<tr>";
                strTableBuild = strTableBuild + "<td>";
                strTableBuild = strTableBuild + fnConvertActivity(Convert.ToInt16(dr[0].ToString()));
                strTableBuild = strTableBuild + "</td>";
                strTableBuild = strTableBuild + "<td>";
                strTableBuild = strTableBuild + dr[1].ToString();
                strTableBuild = strTableBuild + "</td>";
                strTableBuild = strTableBuild + "</tr>";
            }
            strTableBuild = strTableBuild + ("</table>");
            strTableBuild = strTableBuild + ("</div>");
            sqlConn.Close();
            return strTableBuild;
        }
开发者ID:Jefdem1,项目名称:SFActivityTracker,代码行数:35,代码来源:Index.aspx.cs

示例10: cargarUsuario

        public static blc.Usuario cargarUsuario(string usuario)
        {
            blc.Usuario user = new blc.Usuario();
            System.Data.SqlClient.SqlCommand Comando;
            System.Data.SqlClient.SqlDataReader DataReader;
            string query = "SELECT * FROM Usuario WHERE Codigo = '" + usuario + "'";

            Comando = new System.Data.SqlClient.SqlCommand(query);
            Comando.Connection = Program.dt.Connecion;
            Comando.Connection.Open();
            DataReader = Comando.ExecuteReader();

            /* Cargar el objeto con toda su informacion */
            while (DataReader.Read())
            {
                user.Codigo = usuario;
                user.Password = DataReader.GetValue(1).ToString();
                user.Nombre = DataReader.GetValue(2).ToString();
                user.Apellido = DataReader.GetValue(3).ToString();
                user.Celular = DataReader.GetValue(4).ToString();
                user.Email = DataReader.GetValue(5).ToString();
                user.Grupo.Codigo = (int)DataReader.GetValue(6);
                user.Superusuario = DataReader.GetValue(7).ToString();
            }
            DataReader.Close();
            Comando.Connection.Close();
            return user;
        }
开发者ID:BigChief45,项目名称:LawHelper,代码行数:28,代码来源:ccUsuario.cs

示例11: GetKeysInternal

        private static List<KeyInfo> GetKeysInternal(Config config, String connectionString, String keyType)
        {
            Dictionary<String, KeyInfo> keys = new Dictionary<string, KeyInfo>();

            using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectionString))
            {
                conn.Open();
                System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(String.Format("select s.name, o.name, i.name from sys.objects o join sys.indexes i on i.object_id = o.object_id join sys.schemas s on s.schema_id = o.schema_id where i.type_desc = '{0}' and i.is_primary_key = 1 and o.type = 'U' order by 1", keyType), conn);
                using (System.Data.SqlClient.SqlDataReader r = cmd.ExecuteReader())
                {
                    while (r.Read())
                    {
                        String schemaName = r[0].ToString();
                        String tableName = r[1].ToString();
                        String keyName = r[2].ToString();
                        keys.Add((schemaName + tableName).ToLower(), new KeyInfo() { Name = keyName, SchemaName = schemaName, TableName = tableName });
                    }
                }
            }

            Dictionary<String, List<Entity>> schemas = config.EntitiesBySchema;
            List<KeyInfo> result = new List<KeyInfo>();
            foreach (KeyValuePair<String, KeyInfo> kvp in keys)
            {
                if (schemas.ContainsKey(kvp.Value.SchemaName))
                    result.Add(kvp.Value);
            }

            return result;
        }
开发者ID:Fedorm,项目名称:core-master,代码行数:30,代码来源:KeysPatcher.cs

示例12: InitClass

 private void InitClass(int id, int groupID)
 {
     this.RoleID = id;
     this.GroupID = groupID;
     using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[Configuration.ConnectionStringName].ConnectionString))
     {
         using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT * FROM Authorization_RoleToControlGroup WHERE [email protected] AND [email protected]", conn))
         {
             try
             {
                 conn.Open();
                 cmd.Parameters.AddWithValue("@role", id);
                 cmd.Parameters.AddWithValue("@group", groupID);
                 System.Data.SqlClient.SqlDataReader reader = cmd.ExecuteReader();
                 while (reader.Read())
                     this.id = reader.GetInt32(0);
             }
             catch (Exception ex)
             {
                 if (Configuration.s_log != null)
                     Configuration.s_log.Error("[Ошибка модуля авторизации] [Инициализация класса роли группы элементов управления] ", ex);
             }
         }
     }
 }
开发者ID:EkzoMan,项目名称:Ekzo.Security,代码行数:25,代码来源:Ekzo.Web.Security.Utilization.Authorization.ControlsGroupRole.cs

示例13: obtenerCaso

        public static blc.Caso obtenerCaso(string num)
        {
            blc.Caso caso = new blc.Caso();
            System.Data.SqlClient.SqlCommand Comando;
            System.Data.SqlClient.SqlDataReader DataReader;
            string query = "SELECT * FROM Caso WHERE numAccion = '" + num + "'";

            Comando = new System.Data.SqlClient.SqlCommand(query);
            Comando.Connection = Program.dt.Connecion;
            Comando.Connection.Open();
            DataReader = Comando.ExecuteReader();

            while (DataReader.Read())
            {
                caso.NumAccion = DataReader.GetValue(0).ToString();
                caso.Accion = DataReader.GetValue(1).ToString();
                caso.Materia = DataReader.GetValue(2).ToString();
                caso.Oficina = DataReader.GetValue(3).ToString();
                caso.Cliente.ID = DataReader.GetValue(4).ToString();
                caso.Observaciones = DataReader.GetValue(6).ToString();
            }
            DataReader.Close();
            Comando.Connection.Close();
            return caso;
        }
开发者ID:BigChief45,项目名称:LawHelper,代码行数:25,代码来源:ccCaso.cs

示例14: CbBackups_DropDown_1

 private void CbBackups_DropDown_1(object sender, EventArgs e)
 {
     using (var connection = new System.Data.SqlClient.SqlConnection(string.Format("Server={0};Database={1};Trusted_Connection=True;", TxtLocalBkp.Text, TxtDataBase.Text)))
     {
         connection.Open();
         using (var command = new System.Data.SqlClient.SqlCommand(
             "SELECT physical_device_name FROM msdb.dbo.backupmediafamily " +
             "INNER JOIN msdb.dbo.backupset ON msdb.dbo.backupmediafamily.media_set_id = msdb.dbo.backupset.media_set_id " +
             "WHERE (msdb.dbo.backupset.database_name LIKE @DatabaseName)", connection))
         {
             command.Parameters.AddWithValue("DatabaseName", TxtDataBase.Text);
             using (var reader = command.ExecuteReader())
             {
                 var table = new DataTable();
                 table.Load(reader);
                 table.Columns.Add("FriendlyName");
                 foreach (DataRow row in table.Rows)
                 {
                     row["FriendlyName"] = System.IO.Path.GetFileName(row["physical_device_name"].ToString());
                 }
                 if (CbBackups.DataSource != null && CbBackups.DataSource is DataTable)
                 {
                     var oldTable = ((DataTable)CbBackups.DataSource);
                     CbBackups.DataSource = null;
                     oldTable.Dispose();
                 }
                 CbBackups.DataSource = table;
                 CbBackups.DisplayMember = "FriendlyName";
                 CbBackups.ValueMember = "physical_device_name";
             }
         }
     }
 }
开发者ID:mrsalustiano,项目名称:VS_C,代码行数:33,代码来源:FrmBackupBancoDeDados.cs

示例15: SystemRole

        public SystemRole(int baseID, int actionGroup = 0)
        {

            using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[Ekzo.Web.Configuration.UsersStringName].ConnectionString))
            {
                using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT group_name FROM groups WHERE [email protected]", conn))
                {
                    try
                    {
                        conn.Open();
                        cmd.Parameters.AddWithValue("@id", baseID);
                        System.Data.SqlClient.SqlDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
                            this.Role = reader.GetString(0);
                        this.baseID = baseID;
                        this.ActionGroup = actionGroup;
                    }
                    catch (Exception ex)
                    {
                        if (Configuration.s_log != null)
                            Configuration.s_log.Error("[Ошибка модуля авторизации] [Инициализация роли из справочника] ", ex);
                    }
                }
            }
        }
开发者ID:EkzoMan,项目名称:Ekzo.Security,代码行数:25,代码来源:Ekzo.Web.Security.Utilization.Authorization.SystemRole.cs


注:本文中的System.Data.SqlClient.SqlCommand.ExecuteReader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。