public DataTable Buscar(string tipoPesquisa, string pesquisa, string strConn)
        {
            #region Declaração

             SqlConnection conn = null;
             SqlCommand cmd = null;
             SqlDataAdapter da = null;
             DataTable dt = null;
             string sql = string.Empty;

             #endregion

             #region Implementação

             switch (tipoPesquisa)
             {
            default:
               sql = @"SELECT funci.idFuncionario, funci.nome, funci.dataNascimento, funci.email, funci.cpf, funci.rg, funci.ctps, funci.ctpsSerie, funci.telefone, funci.celular,
                funci.cargo, funci.rua, funci.casaNum, funci.Referencia, funci.idCidade, funci.idEstado, funci.LastEditDate, funci.CreationDate, funci.excluido, cid.Nome
                FROM dbo.Funcionario AS funci INNER JOIN Cidade AS cid ON cid.CidadeId = funci.idCidade";
               break;
            case "Matricula":
               sql = @"SSELECT funci.idFuncionario, funci.nome, funci.dataNascimento, funci.email, funci.cpf, funci.rg, funci.ctps, funci.ctpsSerie, funci.telefone, funci.celular,
                funci.cargo, funci.rua, funci.casaNum, funci.Referencia, funci.idCidade, funci.idEstado, funci.LastEditDate, funci.CreationDate, funci.excluido, cid.Nome
                FROM dbo.Funcionario AS funci INNER JOIN Cidade AS cid ON cid.CidadeId = funci.idCidade WHERE funci.idFuncionario = " + pesquisa;
               break;
            case "Nome":
               sql = @"SELECT funci.idFuncionario, funci.nome, funci.dataNascimento, funci.email, funci.cpf, funci.rg, funci.ctps, funci.ctpsSerie, funci.telefone, funci.celular,
                funci.cargo, funci.rua, funci.casaNum, funci.Referencia, funci.idCidade, funci.idEstado, funci.LastEditDate, funci.CreationDate, funci.excluido, cid.Nome
                FROM dbo.Funcionario AS funci INNER JOIN Cidade AS cid ON cid.CidadeId = funci.idCidade WHERE funci.nome LIKE '" + pesquisa + "'";
               break;
            case "CPF":
               sql = @"SELECT funci.idFuncionario, funci.nome, funci.dataNascimento, funci.email, funci.cpf, funci.rg, funci.ctps, funci.ctpsSerie, funci.telefone, funci.celular,
                funci.cargo, funci.rua, funci.casaNum, funci.Referencia, funci.idCidade, funci.idEstado, funci.LastEditDate, funci.CreationDate, funci.excluido, cid.Nome
                FROM dbo.Funcionario AS funci INNER JOIN Cidade AS cid ON cid.CidadeId = funci.idCidade WHERE funci.cpf LIKE '" + pesquisa + "'";
               break;
            case "RG":
               sql = @"SELECT funci.idFuncionario, funci.nome, funci.dataNascimento, funci.email, funci.cpf, funci.rg, funci.ctps, funci.ctpsSerie, funci.telefone, funci.celular,
                funci.cargo, funci.rua, funci.casaNum, funci.Referencia, funci.idCidade, funci.idEstado, funci.LastEditDate, funci.CreationDate, funci.excluido, cid.Nome
                FROM dbo.Funcionario AS funci INNER JOIN Cidade AS cid ON cid.CidadeId = funci.idCidade WHERE funci.rg LIKE '" + pesquisa + "'";
               break;
            case "Ativos":
               sql = @"SELECT funci.idFuncionario, funci.nome, funci.dataNascimento, funci.email, funci.cpf, funci.rg, funci.ctps, funci.ctpsSerie, funci.telefone, funci.celular,
                funci.cargo, funci.rua, funci.casaNum, funci.Referencia, funci.idCidade, funci.idEstado, funci.LastEditDate, funci.CreationDate, funci.excluido, cid.Nome
                FROM dbo.Funcionario AS funci INNER JOIN Cidade AS cid ON cid.CidadeId = funci.idCidade WHERE funci.excluido = 0";
               break;
            case "Inativos":
               sql = @"SELECT funci.idFuncionario, funci.nome, funci.dataNascimento, funci.email, funci.cpf, funci.rg, funci.ctps, funci.ctpsSerie, funci.telefone, funci.celular,
                funci.cargo, funci.rua, funci.casaNum, funci.Referencia, funci.idCidade, funci.idEstado, funci.LastEditDate, funci.CreationDate, funci.excluido, cid.Nome
                FROM dbo.Funcionario AS funci INNER JOIN Cidade AS cid ON cid.CidadeId = funci.idCidade WHERE funci.excluido = 1";
               break;
             }

             try
             {

            conn = new SqlConnection();
            conn.ConnectionString = strConn;

            cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = sql;
            cmd.Connection = conn;

            conn.Open();

            da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            da.GetFillParameters();

            dt = new DataTable();
            da.Fill(dt);

            return dt;

             }
             catch (Exception ex)
             {
            return dt;
             }
             finally
             {
            conn.Close();
             }

             #endregion
        }
Exemplo n.º 2
0
		public void GetFillParametersTest ()
		{
			string query = "select id, type_bit from numeric_family where id > @param1";
			adapter = new SqlDataAdapter (query, connectionString);
			IDataParameter[] param = adapter.GetFillParameters ();
			Assert.AreEqual (0, param.Length, "#1 size shud be 0");
			
			SqlParameter param1 = new SqlParameter ();
			param1.ParameterName = "@param1";
			param1.Value = 2;
			adapter.SelectCommand.Parameters.Add (param1);
		
			param = adapter.GetFillParameters ();
			Assert.AreEqual (1, param.Length, "#2 count shud be 1");
			Assert.AreEqual (param1, param[0], "#3 Params shud be equal");
		}
Exemplo n.º 3
0
        private List<Field> GetReturnColumnsFromProcedure(Procedure proc)
        {
            List<Field> Back = new List<Field>();

            if (proc == null || String.IsNullOrEmpty(proc.Schema) || String.IsNullOrEmpty(proc.Name))
            {
                return Back;
            }

            using (SqlCommand command = new SqlCommand(String.Format("{0}.{1}", proc.Schema, proc.Name), Executor.Connection))
            {
                command.CommandType = System.Data.CommandType.StoredProcedure;
                try
                {
                    command.Connection.Open();
                    SqlCommandBuilder.DeriveParameters(command);
                    SqlDataAdapter Daa = new SqlDataAdapter();
                    Daa.SelectCommand = command;
                    DataSet ds = new DataSet("buff");
                    Daa.GetFillParameters();
                    Daa.FillSchema(ds, SchemaType.Source, "buff");
                    foreach (DataTable tab in ds.Tables)
                    {
                        foreach (DataColumn col in tab.Columns)
                        {
                            if (SqlVsCSharp.ContainsKey(col.DataType.ToString()))
                            {
                                Field aux = new Field()
                                    {
                                        Name = col.Caption,
                                        Type = col.DataType.ToString(),
                                        CSharpType = SqlVsCSharp[col.DataType.ToString()]
                                    };

                                if (!Back.Exists(x => x.Name.Equals(col.Caption, StringComparison.CurrentCultureIgnoreCase)))
                                {
                                    Back.Add(aux);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    command.Connection.Close();
                    MessageBox.Show(ex.Message, "Exception thrown when trying to pull the return data of the Stored Procedure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                command.Connection.Close();
            }
            return Back;
        }
Exemplo n.º 4
0
        public DataTable ExecuteQuerySP(string spName, params object[] parameters)
        {
            SqlCommand command = new SqlCommand();
            command.Connection = dsConn;
            command.CommandText = spName;
            command.CommandType = CommandType.StoredProcedure;

            var dataAdapter = new SqlDataAdapter();
            dataAdapter.SelectCommand = command;
            SqlParameter parameter;
            for (int i = 0; i < parameters.Length; i += 2)
            {
                parameter = command.Parameters.Add(parameters[i].ToString(), Convert2SqlDataType(parameters[i + 1]));
                parameter.Value = parameters[i + 1];
                parameter.Direction = ParameterDirection.Input;
            }
            var dTable = new DataTable();

            try
            {
                dataAdapter.Fill(dTable);
                var fillParameters = dataAdapter.GetFillParameters();
                return dTable;
            }
            catch (Exception)
            {

            }
            finally
            {
                dsConn.Close();
            }

            return dTable;
        }