Answer the question
In order to leave comments, you need to log in
Why can't I change the value of a SQL field in C#?
For some reason, I can’t change the field in SQL, I tried with and without stubs, zero. Here is the code:
public static void Main(string[] args)
{
const string info = "Server=localhost;Database=unturned2;Uid=root;pwd=root;charset=utf8";
MySqlConnection mycon = new MySqlConnection(info);
const string insert = "INSERT INTO wallets (steamid,balance) VALUES (@id , @bal)";
try
{
mycon.Open();
Console.WriteLine("Successfully connected!");
MySqlCommand command = new MySqlCommand(insert, mycon);
command.Parameters.Add("@id", MySqlDbType.VarChar).Value = "76561198928736885";
command.Parameters.Add("@bal", MySqlDbType.Double).Value = 500;
if(command.ExecuteNonQuery() != 1)
{
Console.WriteLine("Error");
}
MySqlCommand changebal = new MySqlCommand("UPDATE wallets SET balance=0 WHERE steamid=76561198928736885", mycon);
if(changebal.ExecuteNonQuery() != 1)
{
Console.WriteLine("Error occured with changing");
}
}
catch(Exception ex)
{
Console.WriteLine($"Error occured, {ex.Message}");
}
finally
{
mycon.Close();
}
}
Answer the question
In order to leave comments, you need to log in
https://dapper-tutorial.net/
string sql = "INSERT INTO wallets (steamid,balance) VALUES (@id , @bal);";
using (var connection = new SqlConnection(info))
{
var affectedRows = connection.Execute(sql, new {id, bal});
Console.WriteLine(affectedRows);
sql = "UPDATE wallets SET balance=0 WHERE [email protected]";
var id =76561198928736885;
var affectedRows = connection.Execute(sql, new {id});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question