Click here to Skip to main content
14,551,100 members
   

C#

 
AnswerRe: recording problem Pin
ZurdoDev17-Mar-20 2:39
mveZurdoDev17-Mar-20 2:39 
GeneralRe: recording problem Pin
OriginalGriff17-Mar-20 2:52
mveOriginalGriff17-Mar-20 2:52 
GeneralRe: recording problem Pin
ZurdoDev17-Mar-20 2:59
mveZurdoDev17-Mar-20 2:59 
GeneralRe: recording problem Pin
Luc Pattyn17-Mar-20 12:08
sitebuilderLuc Pattyn17-Mar-20 12:08 
GeneralRe: recording problem Pin
ago248617-Mar-20 22:04
Memberago248617-Mar-20 22:04 
GeneralRe: recording problem Pin
Luc Pattyn17-Mar-20 22:18
sitebuilderLuc Pattyn17-Mar-20 22:18 
GeneralRe: recording problem Pin
ago248617-Mar-20 23:20
Memberago248617-Mar-20 23:20 
AnswerRe: problem to retrieve an info in a sql request / problème pour recéper une info dans une requête sql Pin
Richard Deeming16-Mar-20 9:28
mveRichard Deeming16-Mar-20 9:28 
As Griff already pointed out, your first command needs to use a parameter. You should also wrap the OleDbCommand object in a using block, and get rid of the ExecuteQuery method.
using (var cmd = sql_con.CreateCommand())
{
    cmd.CommandText = "INSERT INTO Commandes (montant_com) VALUES (@montant_com)";
    cmd.Parameters.AddWithValue("@montant_com", TxtTotalCmd.Text);
    cmd.ExecuteNonQuery();
}
OleDbParameterCollection.AddWithValue(String, Object) Method (System.Data.OleDb) | Microsoft Docs[^]

The second command does not need any parameters. But you do need to execute the command and read the returned value.
long numCmd;
using (var cmd = sql_con.CreateConnection())
{
    cmd.CommandText = "SELECT MAX(num_com) AS dernier_num FROM Commandes";
    
    object result = cmd.ExecuteScalar();
    if (result is null || Convert.IsDBNull(result))
    {
        numCmd = 0L;
    }
    else
    {
        numCmd = Convert.ToInt64(result);
    }
}
OleDbCommand.ExecuteScalar Method (System.Data.OleDb) | Microsoft Docs[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

Generalproblem registering in the access database Pin
ago248617-Mar-20 0:58
Memberago248617-Mar-20 0:58 
GeneralRe: problem registering in the access database Pin
Richard Deeming17-Mar-20 1:01
mveRichard Deeming17-Mar-20 1:01 
GeneralRe: problem registering in the access database Pin
ago248617-Mar-20 1:08
Memberago248617-Mar-20 1:08 
GeneralRe: problem registering in the access database Pin
Richard Deeming17-Mar-20 1:10
mveRichard Deeming17-Mar-20 1:10 
GeneralRe: problem registering in the access database Pin
ago248617-Mar-20 1:17
Memberago248617-Mar-20 1:17 
GeneralRe: problem registering in the access database Pin
Richard Deeming17-Mar-20 1:35
mveRichard Deeming17-Mar-20 1:35 
GeneralRe: problem registering in the access database Pin
ago248617-Mar-20 2:00
Memberago248617-Mar-20 2:00 
GeneralRe: problem registering in the access database Pin
ago248617-Mar-20 1:18
Memberago248617-Mar-20 1:18 
GeneralRe: problem registering in the access database Pin
Richard Deeming17-Mar-20 2:57
mveRichard Deeming17-Mar-20 2:57 
GeneralRe: problem registering in the access database Pin
ago248617-Mar-20 3:14
Memberago248617-Mar-20 3:14 
GeneralRe: problem registering in the access database Pin
ago248617-Mar-20 1:10
Memberago248617-Mar-20 1:10 
GeneralRe: problem registering in the access database Pin
Richard MacCutchan17-Mar-20 2:18
mveRichard MacCutchan17-Mar-20 2:18 
GeneralRe: problem registering in the access database Pin
ago248617-Mar-20 2:26
Memberago248617-Mar-20 2:26 
GeneralRe: problem registering in the access database Pin
Richard MacCutchan17-Mar-20 2:36
mveRichard MacCutchan17-Mar-20 2:36 
QuestionJava Api Callbacks crashes on dotnet framework version 4.5 and above Pin
isaketranjan16-Mar-20 0:06
Memberisaketranjan16-Mar-20 0:06 
AnswerRe: Java Api Callbacks crashes on dotnet framework version 4.5 and above Pin
Gerry Schmitz16-Mar-20 5:05
mveGerry Schmitz16-Mar-20 5:05 
QuestionC# and ODATA CRUD communication with D365BC web service Pin
clemenslinders12-Mar-20 0:13
Memberclemenslinders12-Mar-20 0:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.