Advertisement
Guest User

c# sql connect

a guest
Nov 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10. using System.Security.Cryptography;
  11.  
  12. namespace proba
  13. {
  14. public partial class Form1 : Form
  15. {
  16. SqlConnection connection;
  17. string connectionString = "Server=U2PC07\\SQLEXPRESS; Database=steam; Integrated Security=SSPI;";
  18. SqlCommand command;
  19. SqlDataReader dataReader;
  20. string sql = "SELECT dbo.Game.name, dbo.[User].username FROM dbo.Game INNER JOIN dbo.Library ON dbo.Game.appID = dbo.Library.appID INNER JOIN dbo.[User] ON dbo.[User].idU = dbo.Library.idU";
  21.  
  22. public Form1()
  23. {
  24. InitializeComponent();
  25. connection = new SqlConnection(connectionString);
  26. }
  27.  
  28. private void button1_Click(object sender, EventArgs e)
  29. {
  30. try
  31. {
  32. connection.Open();
  33. command = new SqlCommand(sql, connection);
  34. dataReader = command.ExecuteReader();
  35. string bibl = "";
  36. while (dataReader.Read())
  37. bibl += dataReader.GetValue(1) + " ima igricu " + dataReader.GetValue(0) + Environment.NewLine;
  38.  
  39. MessageBox.Show(bibl);
  40. connection.Close();
  41. }
  42. catch (Exception error)
  43. {
  44. MessageBox.Show("Greska: " + error.ToString());
  45. }
  46.  
  47. }
  48.  
  49.  
  50. private void log_Click(object sender, EventArgs e)
  51. {
  52. string password = passwd.Text;
  53. byte[] encodedPassword = new UTF8Encoding().GetBytes(password);
  54. byte[] hash = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(encodedPassword);
  55. string encoded = BitConverter.ToString(hash).Replace("-", string.Empty);
  56. MessageBox.Show(encoded);
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement