Immusama
Immusama
Explore posts from servers
CC#
Created by Immusama on 3/14/2023 in #help
✅ Help with SQLite INSERT INTO C#
Hey all, I'm running this code and I don't understand why there is no data being stored in my created table.
using System;
using System.IO;
using System.Text;
using System.Data;
using System.Data.SQLite;

public class CPHInline
{
public bool Execute()
{
// Variables
string path = @"Data Source=C:\Users\Immusama\OneDrive - Critical Fear UG (haftungsbeschränkt)\Database\Twitch.db";
string userId = CPH.GetGlobalVar<string>("userId", true);
string userName = CPH.GetGlobalVar<string>("userName", true);
string displayName = CPH.GetGlobalVar<string>("user", true);
int isSubscribed = CPH.GetGlobalVar<int>("isSubscribed", true);
int isVip = CPH.GetGlobalVar<int>("isVip", true);
int isModerator = CPH.GetGlobalVar<int>("isModerator", true);

SQLiteConnection sql_db = new SQLiteConnection(path);


sql_db.Open();
string sql = "CREATE TABLE Viewers (userId varchar(20), userName varchar(30), displayName varchar(30), isSubscribed int, isVip int, isModerator int)";
SQLiteCommand command = new SQLiteCommand(sql, sql_db);
command.ExecuteNonQuery();


SQLiteCommand sqlInsert = new SQLiteCommand ("INSERT INTO Viewers (userId, userName, displayName, isSubscribed, isVip, isModerator) VALUES (@userId, @userName, @displayName, @isSubscribed, @isVip, @isModerator)", sql_db);
sqlInsert.Parameters.AddWithValue(@"userId", userId);
sqlInsert.Parameters.AddWithValue(@"userName", userName);
sqlInsert.Parameters.AddWithValue(@"displayName", displayName);
sqlInsert.Parameters.AddWithValue(@"isSubscribed", isSubscribed);
sqlInsert.Parameters.AddWithValue(@"isVip", isVip);
sqlInsert.Parameters.AddWithValue(@"isModerator", isModerator);

sql_db.Close();

return true;
}
}
using System;
using System.IO;
using System.Text;
using System.Data;
using System.Data.SQLite;

public class CPHInline
{
public bool Execute()
{
// Variables
string path = @"Data Source=C:\Users\Immusama\OneDrive - Critical Fear UG (haftungsbeschränkt)\Database\Twitch.db";
string userId = CPH.GetGlobalVar<string>("userId", true);
string userName = CPH.GetGlobalVar<string>("userName", true);
string displayName = CPH.GetGlobalVar<string>("user", true);
int isSubscribed = CPH.GetGlobalVar<int>("isSubscribed", true);
int isVip = CPH.GetGlobalVar<int>("isVip", true);
int isModerator = CPH.GetGlobalVar<int>("isModerator", true);

SQLiteConnection sql_db = new SQLiteConnection(path);


sql_db.Open();
string sql = "CREATE TABLE Viewers (userId varchar(20), userName varchar(30), displayName varchar(30), isSubscribed int, isVip int, isModerator int)";
SQLiteCommand command = new SQLiteCommand(sql, sql_db);
command.ExecuteNonQuery();


SQLiteCommand sqlInsert = new SQLiteCommand ("INSERT INTO Viewers (userId, userName, displayName, isSubscribed, isVip, isModerator) VALUES (@userId, @userName, @displayName, @isSubscribed, @isVip, @isModerator)", sql_db);
sqlInsert.Parameters.AddWithValue(@"userId", userId);
sqlInsert.Parameters.AddWithValue(@"userName", userName);
sqlInsert.Parameters.AddWithValue(@"displayName", displayName);
sqlInsert.Parameters.AddWithValue(@"isSubscribed", isSubscribed);
sqlInsert.Parameters.AddWithValue(@"isVip", isVip);
sqlInsert.Parameters.AddWithValue(@"isModerator", isModerator);

sql_db.Close();

return true;
}
}
31 replies
CC#
Created by Immusama on 3/13/2023 in #help
❔ How do I store data properly?
So I'm streaming on Twitch and I have a program called Streamer.Bot which allows me to use C# to execute code. I have a very basic and limited understanding about C# and coding in general ~ what I'm trying to do is store my viewers data in specific categories I define myself. The main problem I'm having is understanding how to store the acquired data into a file (I haven't figured out another way yet, either .txt, .csv or .ini). An example how I'm imagining it: .ini file is named after my viewer's username in a folder with all the others:
[section1]
key1="value"
key2="value"

[section2]
key1="value"
key2="value"
[section1]
key1="value"
key2="value"

[section2]
key1="value"
key2="value"
I wanna be able to read it and override specific keys if I so desire. (Most of it is automatic) To sum it up, I know how to write it into a file but I don't know how to format it properly and check for specific sections and key+values and override them.
7 replies