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.Text;
- using System.Threading.Tasks;
- using System.Data.SqlClient;
- namespace UsersDataAccess
- {
- class Program
- {
- static void Main(string[] args)
- {
- SqlConnection conn = new SqlConnection();
- conn.ConnectionString = @"Server=localhost;Database=MyDatabase;Trusted_Connection=True;";
- // database seesiq e vremeto mejdu otvarqne na edna vruzka i zatvarqneto
- SqlCommand cmd = new SqlCommand();
- cmd.Connection = conn;
- cmd.CommandText = @"
- SELECT
- Id,
- Username,
- Password,
- FirstName,
- LastName
- FROM
- Users
- WHERE
- Username = AND Password = ";
- SqlDataReader reader = null;
- try
- {
- conn.Open();
- reader = cmd.ExecuteReader();
- while (reader.Read() == true) // vrushta true (uspeshno e prochel zapisa ot database) ili false (ne e uspeshno, ne e prochel danni)
- {
- Console.WriteLine(reader["Id"].ToString());
- Console.WriteLine(reader["Username"].ToString());
- Console.WriteLine(reader["Password"].ToString());
- Console.WriteLine(reader["FirstName"].ToString());
- Console.WriteLine(reader["LastName"].ToString());
- Console.WriteLine("**********");
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- finally
- {
- reader.Close();
- conn.Close();
- }
- Console.ReadKey(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement