koopa
koopa
CC#
Created by koopa on 12/18/2022 in #help
❔ ContextSwitchDeadlock
Hi - in my windows form program I generate some RSA keys before the program loads, this takes around 2 minutes though and after 60 seconds the program crashes due to taking too long - how would I go about preventing this? I don't know much about threads and stuff
6 replies
CC#
Created by koopa on 10/19/2022 in #help
Collection was modified enumeration operation may not execute
5 replies
CC#
Created by koopa on 10/8/2022 in #help
SQL Error when trying to get an ID
I'm trying to add username password and email to my users table And then get the ID of this new user.
SqlCommand cmd = new SqlCommand("insert into Users values(@username,@password,@email)", cn);
cmd.Parameters.AddWithValue("username", info["username"]);
cmd.Parameters.AddWithValue("password", encryptedPW);
cmd.Parameters.AddWithValue("email", info["email"]);
int id = (int)cmd.ExecuteScalar();
SqlCommand cmd = new SqlCommand("insert into Users values(@username,@password,@email)", cn);
cmd.Parameters.AddWithValue("username", info["username"]);
cmd.Parameters.AddWithValue("password", encryptedPW);
cmd.Parameters.AddWithValue("email", info["email"]);
int id = (int)cmd.ExecuteScalar();
however I get this error:
System.Data.SqlClient.SqlException: 'Column name or number of supplied values does not match table definition.'
System.Data.SqlClient.SqlException: 'Column name or number of supplied values does not match table definition.'
1 replies
CC#
Created by koopa on 10/7/2022 in #help
SQL and Visual Studio Retrieving a Table
Hi - I'm trying to select all the "emails" in a table called "users" with c# in visual studio. Currently I have this command:
SqlCommand cmd = new SqlCommand("select email from Users", cn);
SqlCommand cmd = new SqlCommand("select email from Users", cn);
I'm not sure how to get the data from this though, would it be doing smth like:
List<string> emails = cmd.Execute();
List<string> emails = cmd.Execute();
?
18 replies
CC#
Created by koopa on 9/27/2022 in #help
Prevent scrollbar from jumping down when viewing a list?
Hi - I'm making a chat room in windows forms and have a listbox that displays all the messages recieved, ofcourse I have the chatbox set to automatically scroll to the bottom when a new item is sent. However, if the user is looking at old messages and a new item is sent, the scroll bar immediately jumps to the bottom. I was thinking that I could do something like if(scrollBarPosition > scrollBarBottom) doNotJumpToBottom except I can't seem to find any scroll bar position variable. This is my jump to the bottom code:
chatListBox.TopIndex = chatListBox.Items.Count - 1;
chatListBox.TopIndex = chatListBox.Items.Count - 1;
1 replies
CC#
Created by koopa on 9/23/2022 in #help
Disconnect a client from a TCPServer csharp
Hi - I have a basic client server chat room model which I'm working on for a school project. I'm trying to program a /kick feature to disconnect a client from the server, however TCPClient.Close() and TCPClient.Client.Disconnect() do not seem to be working - as in the client thinks that it is still connected, not sure whether I just need to update the client that it is not connected or whether I should use a different disconnect method.
7 replies
CC#
Created by koopa on 9/14/2022 in #help
Not sure how the byte[] works in Csharp
Hi, basically I have a very simple program which I'm using to try and understand how bytes work:
namespace Encryptor
{
class Program
{

static void Main(string[] args)
{
string plainText = "Test";
byte[] plainBytes;
plainBytes = ObjectToByteArray(plainText);
foreach(int i in plainBytes)
{
Console.WriteLine(i);
}
}
public static byte[] ObjectToByteArray(Object obj)
{

BinaryFormatter bf = new BinaryFormatter();
using (var ms = new MemoryStream())
{
bf.Serialize(ms, obj);
return ms.ToArray();
}
}
}

}
namespace Encryptor
{
class Program
{

static void Main(string[] args)
{
string plainText = "Test";
byte[] plainBytes;
plainBytes = ObjectToByteArray(plainText);
foreach(int i in plainBytes)
{
Console.WriteLine(i);
}
}
public static byte[] ObjectToByteArray(Object obj)
{

BinaryFormatter bf = new BinaryFormatter();
using (var ms = new MemoryStream())
{
bf.Serialize(ms, obj);
return ms.ToArray();
}
}
}

}
It is my understanding that the integers printed should be the 4 ascii values for "Test" and nothing more, instead this is printed (grouped into sets of 4 for easier reading):
0 1 0 0 0 255 255 255 255 1 0 0 0 0 0 0 0 6 1 0 0 0 4 84 101 115 116 11
0 1 0 0 0 255 255 255 255 1 0 0 0 0 0 0 0 6 1 0 0 0 4 84 101 115 116 11
And I am unsure as to why, could anyone be of assistance please
9 replies