How to Save Radiobutton to Oracle

Asked

Viewed 147 times

0

How do I save only the marked Radiobutton? Images below what I did. He’s saving one value, even though I marked the other.In my database I have to create a single field to save any of the information?

Note: I am using Visual Studio(C#) and SQL Developer (Oracle)

inserir a descrição da imagem aqui

bank code:

create table Mesa
(
  cod number(5)not null,
  nome VARCHAR2(20)not null,
  ativa VARCHAR2(20)not null,
  inativa VARCHAR2(20)not null,
  Ativo number(03)not null,
  constraint PK_cod_Mesa PRIMARY KEY(cod)
);

C#:

public void Gravar()
{
    string strQuery;
    strQuery = "INSERT INTO Mesa";
    strQuery += (" VALUES(");
    strQuery += ("seq_mesa.NEXTVAL,");
    strQuery += ("'" + _nome + "',");
    strQuery += ("'" + _ativa + "',"); //campo onde irei salvar o ativa ou inativa
    strQuery += ("'1'");
    strQuery += (")");

    clnBancoDados ObjClnBancoDados = new clnBancoDados();
    ObjClnBancoDados.ExecutaComando(strQuery);
}

I declared them upon this way:

public string ativa
{
    get { return _ativa; }
    set { _ativa = value; }
}

public string inativa
{
    get { return _inativa; }
    set { _inativa = value; }
}
  • Young man, somewhere you assigns some value to this property (_ativa)?

  • Radionbutton vc inserted as individual objects or is a group - Radiobuttonlist?

  • I got it. VLW.

1 answer

0

class: c#

class clnCadastro {

private int _Cod;

    public int Cod
    {
        get { return _cod; }
        set { _cod = value; }
    }

    private string _nome;

    public string Nome
    {
        get { return _nome; }
        set { _nome = value; }
    }

    private int _ativo;

    public int Ativo // receberá 0 para inativo ou 1 para ativo
    {
        get { return _ativo; }
        set { _ativo = value; }
    }
}

public Dataset Filler() //for combobox { string strQuery; strQuery = "Select cod_active From T_active"; cldBancoOobjBancoDados = new cldBancoDados(); Return dataset(strQuery);

    } 

public Oracledatareader Preencherativocomreader(string strNome) //for radiobutton { string strQuery; strQuery = "Select t_a.Description From t_active t_a Inner Join mesa t_m on t_a.cod_active = t_m.Active" Where t_m.name='strNome'; cldBancoOobjBancoDados = new cldBancoDados(); Return datareader(strQuery); }

public void Save() { string strQuery; strQuery = "INSERT INTO Mesa"; strQuery += (" VALUES("); strQuery += ("table.NEXTVAL"); strQuery += ("'" + _name + "',"); strQuery += ("'" + _active + "',"); //field where I will save the active or inactive strQuery += (")");

clnBancoDados ObjClnBancoDados = new clnBancoDados();
ObjClnBancoDados.ExecutaComando(strQuery);

}

c#

private void btnSalvar_Click(Object Sender, Eventargs and) { clnCadastro cadastro = new clnCadastro(); register.name = txtName;

        if (radioButtonAtivo.Checked == true)
        {
            cadastro.ativo = 1;
        }

        else if (radioButtonInativo.Checked == true) 
        {
            cadastro.ativo = 0;
        }

public void Filler() // to use in modify, with combobox { clnCartiro cadastro= new clnCadastro (); comboBoxAtivo.Datasource = registration.Filler(). Tables[0]; comboBoxAtivo.Valuemember = "cod_Ativo"; comboBoxAtivo.Displaymember = "Description"; comboBoxAtivo.Selectedindex = -1; // to go blank before //to select

//or modify with radiobutton clnCartiro cadastro= new clnCadastro (); Oracledatareader drDados; string name = register.name; drDados = registration.Filledvocomreader(name); if (drDados.Read()) { if (drDados["Description"].toString() == "ACTIVE") { radioButtonAtivo.Checked = true; }

            else if (drDados["descricao"].toString() == "INATIVO")
            {
                radioButtonInativo.Checked = true;
            }




    }

Bench:

create table table table ( Cod number(5), name VARCHAR2(20)not null, Active number(1)not null, Constraint Pk_cod_mesa PRIMARY KEY(Cod) contraint fk_cod_active Foreign key (active) References T_active(cod_Ativo ) );

create table T_active ( cod_Ativo number (1), Description char(7),

Constraint Pk_cod_active PRIMARY KEY(Active) );

Insert into T_ativo values(1,'ASSET'); Insert into T_active values(0,'INACTIVE');

then you save 0 for inactive and 1 for active in the bank and in modifying it will return the texts to you instead of the numbers

active inactive

hope I’ve helped

Browser other questions tagged

You are not signed in. Login or sign up in order to post.