Olá a todos, estou começando o estudos da plataforma .net. Gostaria de saber como comparar dois valores um digitado por usuario e outro contido no banco de dados. - Fiz a conexão com o banco de dados: Dim strConexao As String Dim strSQL As String strSQL = "Select Log_id as Codigo, Log_Usuario as Usuario, Log_Nome as Nome from Tab_Login" strConexao = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = (NOME DO BANCO)" Dim objConexao As New OleDbConnection(strConexao) Dim objCommand As New OleDbCommand(strSQL, objConexao) Dim dr As OleDbDataReader objConexao.Open() dr = objCommand.ExecuteReader() gostaria de verificar se o usuario e a senha estão corretos If ( tUsuario.tex == (campo da tabela Log_usuario ) ' INSTRUÇÕES ..... End Ifestou com problema na hora de comparar os valores e verificar se a conexão com o banco esta OK Muito obrigado
Aqui, veremos como podemos comparar as colunas de duas tabelas diferentes em SQL. Daremos alguns exemplos para ver como podemos fazer isso de maneiras diferentes. Visão geral: Etapa 1: Criando o banco de dados: Sintaxe - create database_name;Exemplo - Etapa 2: Usando o banco de dados: Sintaxe - use database_name;Exemplo - use STUDENT_DATAEtapa 3: Criando a tabela: Tabela 1: Sintaxe - create table table_name ( column1 type, column2 type, ... );Exemplo - create table studentData1 ( roll_number int primary key, firstname varchar(100), lastname varchar(100), marks int );Passo 4: Inserindo registros: Inserindo registros na tabela studentData1 como segue. Sintaxe - Inserindo na tabela studentData1 - insert into studentData1 (roll_number, firstname, lastname, marks) values (1, 'albert', 'einstein',356); insert into studentData1 (roll_number, firstname, lastname, marks) values (2, 'isaac', 'newton',412); insert into studentData1 (roll_number, firstname, lastname, marks) values (3, 'marie', 'curie',436); insert into studentData1 (roll_number, firstname, lastname, marks) values (4, 'philip', 'jsam',389); insert into studentData1 (roll_number, firstname, lastname, marks) values (5, 'tom', 'jsam',452); insert into studentData1 (roll_number, firstname, lastname, marks) values (6, 'tucker', 'jose',412); insert into studentData1 (roll_number, firstname, lastname, marks) values (7, 'drawn', 'csate',389);Etapa 5: Criando a tabela2: Passo 6: Inserindo registros: Exemplo-1: Usando a cláusula where para comparar colunas de duas tabelas diferentes. Ele não pode lidar com os valores nulos. Sintaxe: (para selecionar todos os registros com todas as colunas) select * from table1, table where table1.col1 = table2.col2 and table1.col1 > someValue; Sintaxe (alternativa): Consulta - select * from studentData1, studentData2 where studentData1.roll_number = studentData2.id;Saída:
Exemplo-2: Sintaxe - select t1.col1, t1.col2... , t2.col1, t2.col2... , from table1 as t1 left join table2 as t2 on tabe1.col1 = table2.col1;Consulta - select a.roll_number, a.firstname, b.id from studentData1 as a left join studentData2 as b on a.roll_number = b.id;Saída:
Exemplo-3: Nota - Sintaxe - select col1, col2, col3 .... from (select col1, col2, col3 ... from Table1 union all select col1, col2, col3 ... from Table2) cmpr order by ID;Exemplo - Saída:
This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
|