Skip to content

Commit ef605a1

Browse files
Added database
1 parent 841ffb4 commit ef605a1

File tree

191 files changed

+208544
-66
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+208544
-66
lines changed

Blog(Dirty)/Blog(Dirty).csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111
<ItemGroup>
1212
<Compile Remove="EFCoreAccess.cs" />
13-
<Compile Remove="UserRepository.cs" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
1417
</ItemGroup>
1518

1619
</Project>

Blog(Dirty)/Program.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
using Blog_Dirty_;
22

3-
Console.Write("Write a username: ");
4-
string username = Console.ReadLine();
5-
Console.Write("Write a password: ");
6-
string password = Console.ReadLine();
7-
3+
namespace Blog_Dirty_
4+
{
5+
sealed class Program
6+
{
7+
private static UserManager userManager = new UserManager();
8+
static void Main(string[] args)
9+
{
10+
Console.Write("Write a username: ");
11+
string username = Console.ReadLine();
12+
Console.Write("Write a password: ");
13+
string password = Console.ReadLine();
14+
}
15+
}
816

17+
}

Blog(Dirty)/UserManager.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Data.SqlClient;
7+
using System.Data;
8+
9+
namespace Blog_Dirty_
10+
{
11+
internal class UserManager
12+
{
13+
private static SqlConnection connection = new SqlConnection();
14+
private static string databaseSource = "Data Source=(local);Initial Catalog=UserRepository;Integrated Security=True";
15+
public void createDatabase()
16+
{
17+
connection.ConnectionString = databaseSource;
18+
connection.Open();
19+
}
20+
21+
public void closeDatabase()
22+
{
23+
connection.Close();
24+
}
25+
26+
private static SqlDataAdapter adapter = new SqlDataAdapter();
27+
public int executeDataAdapter(DataTable tblName, string databaseCommands)
28+
{
29+
if (connection.State == 0)
30+
{
31+
createDatabase();
32+
}
33+
34+
adapter.SelectCommand.CommandText = databaseCommands;
35+
adapter.SelectCommand.CommandType = CommandType.Text;
36+
SqlCommandBuilder DbCommandBuilder = new SqlCommandBuilder(adapter);
37+
38+
string insert = DbCommandBuilder.GetInsertCommand().CommandText.ToString();
39+
string update = DbCommandBuilder.GetUpdateCommand().CommandText.ToString();
40+
string delete = DbCommandBuilder.GetDeleteCommand().CommandText.ToString();
41+
42+
return adapter.Update(tblName);
43+
}
44+
45+
private static SqlCommand command = new SqlCommand();
46+
public void readDataFromCommands(string query, DataTable tblName)
47+
{
48+
command.Connection = connection;
49+
command.CommandText = query;
50+
command.CommandType = CommandType.Text;
51+
52+
adapter = new SqlDataAdapter(command);
53+
adapter.Fill(tblName);
54+
}
55+
56+
private static SqlDataReader readDataFromStream(string query)
57+
{
58+
SqlDataReader reader;
59+
60+
command.Connection = connection;
61+
command.CommandText = query;
62+
command.CommandType = CommandType.Text;
63+
64+
reader = command.ExecuteReader();
65+
return reader;
66+
}
67+
68+
public int executeQuery(SqlCommand dbCommand)
69+
{
70+
dbCommand.Connection = connection;
71+
dbCommand.CommandType= CommandType.Text;
72+
73+
return dbCommand.ExecuteNonQuery();
74+
}
75+
}
76+
}

Blog.Tests/Blog.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<PackageReference Include="NUnit" Version="3.14.0" />
2020
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
2121
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
22+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
2223
</ItemGroup>
2324

2425
<ItemGroup>

Database/Database.sqlproj

Lines changed: 0 additions & 60 deletions
This file was deleted.
38.7 KB
Binary file not shown.
1.49 MB
Binary file not shown.
88.7 KB
Binary file not shown.
Binary file not shown.
28.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)