kevin
kevin
CC#
Created by kevin on 1/14/2024 in #help
Trying to implement SQL database in my app
Hello I'm trying to implement SQLite in my application, my professor has provided me with sample code but whenever i try to implement it i get the error seen in the screenshot, i suppose the package cant find my database file ? Heres the code im using: Constants.cs
public static class Constants
{
private const string dBFileName = "database.db3";

public const SQLiteOpenFlags flags =
SQLiteOpenFlags.ReadWrite |
SQLiteOpenFlags.Create |
SQLiteOpenFlags.SharedCache;

public static string DatabasePath
{
get
{
Console.WriteLine(FileSystem.AppDataDirectory, dBFileName);
return Path.Combine(FileSystem.AppDataDirectory, dBFileName);
}
}
}
public static class Constants
{
private const string dBFileName = "database.db3";

public const SQLiteOpenFlags flags =
SQLiteOpenFlags.ReadWrite |
SQLiteOpenFlags.Create |
SQLiteOpenFlags.SharedCache;

public static string DatabasePath
{
get
{
Console.WriteLine(FileSystem.AppDataDirectory, dBFileName);
return Path.Combine(FileSystem.AppDataDirectory, dBFileName);
}
}
}
4 replies
CC#
Created by kevin on 1/13/2024 in #help
Tabbed pages in MAUI
Hello I'm trying to create a TabbedPage in MAUI using the following code:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Project.View.DashboardView"
xmlns:local="clr-namespace:Project.View">

<local:GameView Title="Game" />

</TabbedPage>
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Project.View.DashboardView"
xmlns:local="clr-namespace:Project.View">

<local:GameView Title="Game" />

</TabbedPage>
I get 2 errors: Partial declarations of 'DashboardView' must not specify different base classes and Argument 1: cannot convert from 'Project.View.DashboardView' to 'Microsoft.Maui.Controls.Page If i change <TabbedPage> to ContentPage it works. Here's the line of code where the error occurs:
private void DashboardBtn_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new DashboardView());
}
private void DashboardBtn_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new DashboardView());
}
5 replies
CC#
Created by kevin on 1/11/2024 in #help
Problems with creating a new ContentPage in .NET MAUI
Hello I'm trying to make a dashboard view in .NET MAUI using a content page. Once I generate it it says: "the name 'InitializeComponent' does not exist in the current context." I have tried rebuilding the solution and re-opening my project but I have no clue on how to fix this.
3 replies
CC#
Created by kevin on 12/15/2023 in #help
Cant play video in MAUI
Hey I'm trying to play a background video in MAUI, my underlying code is:
<toolkit:MediaElement x:Name="BgVideo" Source="Resources/Raw/video.mp4" ShouldShowPlaybackControls="False"
ShouldLoopPlayback="True" Aspect="AspectFill" ShouldAutoPlay="True"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
<toolkit:MediaElement x:Name="BgVideo" Source="Resources/Raw/video.mp4" ShouldShowPlaybackControls="False"
ShouldLoopPlayback="True" Aspect="AspectFill" ShouldAutoPlay="True"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
however it doesn't play the video if i change the path to a URL it works fine, is my path wrong ?
6 replies
CC#
Created by kevin on 7/12/2023 in #help
✅ Issues with setting up different classes and sql connection
Could someone help me understand how I can setup this SQL connection? it's my first time organizing my code into different folders and really structuring my app with different folders, etc. I get the error "A field initializer cannot reference the non-static field, method or property 'Customer.connection' ". I want to make it so that I have a connection class that handles the connection. Currently I have: model class that talks to the dal class that talks to the connection class I have the following class:
public class Customer : ICustomer
{
private Connection connection;
CustomerDAO db = new CustomerDAO(connection.CreateConnection());
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Address { get; set; }

// ctor
public Customer(....)
{
.........
}

public void Create(Customer customer)
{
db.Create(customer)
}
public class Customer : ICustomer
{
private Connection connection;
CustomerDAO db = new CustomerDAO(connection.CreateConnection());
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Address { get; set; }

// ctor
public Customer(....)
{
.........
}

public void Create(Customer customer)
{
db.Create(customer)
}
My connection class looks like this
public class Connection
{
private string connectionString = "example string";

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

public SqlConnection CreateConnection()
{
SqlConnection connection = new SqlConnection(connectionString);
return connection;
}
}
35 replies
CC#
Created by kevin on 6/15/2023 in #help
❔ Getting SQL data from a relationship table
6 replies
CC#
Created by kevin on 3/11/2023 in #help
❔ Misused header name
Hi, I get the following error and I'm not sure on how to fix it.
System.InvalidOperationException: 'Misused header name, 'content-type'. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.'
System.InvalidOperationException: 'Misused header name, 'content-type'. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.'
Heres my code:
using var httpClient = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri($"https://api.openai.com/v1/{_model}/completions"),
Headers =
{
{ "Content-Type", "application/json" },
{ "Authorization", $"Bearer {_apiKey}" },
},
Content = new StringContent(JsonSerializer.Serialize(new
{
prompt = question,
max_tokens = 50,
temperature = 0.7
}))
};
using var httpClient = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri($"https://api.openai.com/v1/{_model}/completions"),
Headers =
{
{ "Content-Type", "application/json" },
{ "Authorization", $"Bearer {_apiKey}" },
},
Content = new StringContent(JsonSerializer.Serialize(new
{
prompt = question,
max_tokens = 50,
temperature = 0.7
}))
};
5 replies