Jump to content

Recommended Posts

Posted

boas,

tenho 3 tabelas numa bd

utilizadores,alunos,professores

as 3 tabelas tem o id_user, no utilizadores e primaria nas outras e secundaria

no c# tenho uma ligacao e um comando SELECT para verificar se o id_user actual existe na tabela alunos ou professore, se tiver retorna o valor do id, se nao tiver nao retorna nada, a minha duvida e a seguinte

eu tenho que verificar se retorna ou nao alguma coisa para fazer um ciclo:

                SqlConnection conn = new SqlConnection(connectionString);
                conn.Open();
                SqlCommand cmd = new SqlCommand("SELECT id_user FROM alunos WHERE (id_user = @id_User) UNION SELECT id_user FROM professores WHERE (id_user = @id_User)", conn);
                cmd.Parameters.Add("@id_User", SqlDbType.NVarChar).Value = txtid_user.Text;
                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.SelectCommand = cmd;
                DataTable ds = new DataTable();
                adapter.Fill(ds);
                txtid_user.DataBindings.Add("Text", ds, "id_user");
                //
                SqlDataReader dr1 = cmd.ExecuteReader();
                while (dr1.Read())
                {
                    
                }

o codigo e este, so que agora preciso de verificar dentro do while, alguma segestao ?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.