kevin
kevin
CC#
Created by kevin on 1/14/2024 in #help
Trying to implement SQL database in my app
No description
4 replies
CC#
Created by kevin on 1/14/2024 in #help
Trying to implement SQL database in my app
Gamerepository.cs
public class GameRepository
{
SQLiteConnection connection;
public GameRepository()
{
connection = new SQLiteConnection(

Constants.DatabasePath,
Constants.flags);
connection.CreateTable<Game>();
}

public void Add(Game game)
{
int result = 0;
try
{
result = connection.Insert(game);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

public List<Game>? Read()
{
try
{
return connection.Table<Game>().ToList();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return null;
}
}
public class GameRepository
{
SQLiteConnection connection;
public GameRepository()
{
connection = new SQLiteConnection(

Constants.DatabasePath,
Constants.flags);
connection.CreateTable<Game>();
}

public void Add(Game game)
{
int result = 0;
try
{
result = connection.Insert(game);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

public List<Game>? Read()
{
try
{
return connection.Table<Game>().ToList();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return null;
}
}
4 replies
CC#
Created by kevin on 1/13/2024 in #help
Tabbed pages in MAUI
namespace Project.View;

public partial class DashboardView : ContentPage
{
public DashboardView()
{
InitializeComponent();
}
}
namespace Project.View;

public partial class DashboardView : ContentPage
{
public DashboardView()
{
InitializeComponent();
}
}
5 replies
CC#
Created by kevin on 1/11/2024 in #help
Problems with creating a new ContentPage in .NET MAUI
No, also happens when I generate a new one
3 replies
CC#
Created by kevin on 12/15/2023 in #help
Cant play video in MAUI
Thanks!
6 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
Usually i would store it somewhere in .env right ?
35 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
This is for a school project so I’m not really worried about safety that much just wondering
35 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
Wondering though and correct me if im wrong but isnt making it static unsafe because im storing my sql connection string in there ? any object could access the sql connection or am i wrong ?
35 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
Ah okay, it works now, thanks
35 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
currently doing it like this using (SqlConnection sqlConnection = connection.CreateConnection())
35 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
How would i use the connection now ?
35 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
35 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
like this
public static class Connection
{
public static SqlConnection CreateConnection()
{
SqlConnection connection = new SqlConnection("example string");
return connection;
}
}
public static class Connection
{
public static SqlConnection CreateConnection()
{
SqlConnection connection = new SqlConnection("example string");
return connection;
}
}
35 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
Wait so I would remove the connectionString then
35 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
public static class Connection
{
private static string connectionString = "example string";

public static SqlConnection CreateConnection()
{
SqlConnection connection = new SqlConnection(connectionString);
return connection;
}
}
public static class Connection
{
private static string connectionString = "example string";

public static SqlConnection CreateConnection()
{
SqlConnection connection = new SqlConnection(connectionString);
return connection;
}
}
35 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
35 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
here's the code
public class CustomerDAO
{
private Connection connection;

public CustomerDAO(Connection connection)
{
this.connection = connection;
}

#region Create
public void Create(Customer customer)
{
using (SqlConnection sqlConnection = connection.CreateConnection())
{
sqlConnection.Open();
string query = "INSERT INTO Customer (Name, Email, Phone, Address) VALUES (@Name, @Email, @Phone, @Address)";
SqlCommand command = new SqlCommand(query, sqlConnection);
command.Parameters.AddWithValue("@Name", customer.Name);
command.Parameters.AddWithValue("@Email", customer.Email);
command.Parameters.AddWithValue("@Phone", customer.Phone);
command.Parameters.AddWithValue("@Address", customer.Address);
command.ExecuteNonQuery();
}
}
#endregion
public class CustomerDAO
{
private Connection connection;

public CustomerDAO(Connection connection)
{
this.connection = connection;
}

#region Create
public void Create(Customer customer)
{
using (SqlConnection sqlConnection = connection.CreateConnection())
{
sqlConnection.Open();
string query = "INSERT INTO Customer (Name, Email, Phone, Address) VALUES (@Name, @Email, @Phone, @Address)";
SqlCommand command = new SqlCommand(query, sqlConnection);
command.Parameters.AddWithValue("@Name", customer.Name);
command.Parameters.AddWithValue("@Email", customer.Email);
command.Parameters.AddWithValue("@Phone", customer.Phone);
command.Parameters.AddWithValue("@Address", customer.Address);
command.ExecuteNonQuery();
}
}
#endregion
35 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
Currently I get alot of errors in my customerDAO class
35 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
would i make the entire class static or just the connectionstring ?
35 replies