Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.ServiceModel.Web;
- using System.Text;
- using System.Data;
- using System.Data.Sql;
- using System.Data.SqlClient;
- namespace WcfService1
- {
- public class Service1 : IPractico1
- {
- /// <summary>
- /// Verifica si el usuario esta dentro de la base de datos.
- /// </summary>
- /// <param name="userName">Nombre de usuario a buscar.</param>
- /// <returns>True or False</returns>
- public bool ExisteUsuario(string userName)
- {
- //OJO ING.!
- //Obviamente todo este codigo deberia ir en una capa de accesso a datos.
- //Pero por la simplicidad del ejercicio, creo que no amerita tanta arquitectura. :P
- //Configuramos toda la informacion necesaria para la coneccion SQL.
- string Server = "localhost";
- string Username = "sergiolas";
- string Password = "1234";
- string Database = "dapcuatro";
- string ConnectionString = "Data Source=" + Server + ";";
- ConnectionString += "User ID=" + Username + ";";
- ConnectionString += "Password=" + Password + ";";
- ConnectionString += "Initial Catalog=" + Database;
- var dbConnection = new SqlConnection();
- try
- {
- dbConnection.ConnectionString = ConnectionString;
- dbConnection.Open();
- }
- catch (Exception ex)
- {
- if (dbConnection != null)
- {
- dbConnection.Dispose();
- }
- string error = "No se pudo iniciar la coneccion SQL.";
- error += Environment.NewLine;
- error += Environment.NewLine;
- error += ex.Message;
- }
- //Aqui lo que decidi hacer es hacer un select * de la table de Usuarios y logicamente,
- //si existe el usuario solicitado el datatable va tener mas de 0 rows.
- string sentenciaSQL = "Select * from Usuarios where userID = " + userName;
- var dbAdapter = new SqlDataAdapter(sentenciaSQL, dbConnection);
- var dtResultado = new DataTable();
- dbAdapter.Fill(dtResultado);
- if (dtResultado.Rows.Count > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement