Decrement value by 1 MS Access SQL and C# [duplicate]
This question already has an answer here:
How can I add user-supplied input to an SQL statement?
2 answers
I'm facing a problem with decrementing value with MS Access database.
I get an error
Syntax error in UPDATE Statement
My code:
connection.Open();
command = new OleDbCommand();
command.Connection = connection;
command.CommandText = " update Cards set Count = Count - 1 where Type=" + ct + " ";
command.ExecuteNonQuery();
connection.Close();
Can anyone please help?
c# sql ms-access
marked as duplicate by LarsTech
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 13 '18 at 17:20
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 6 more comments
This question already has an answer here:
How can I add user-supplied input to an SQL statement?
2 answers
I'm facing a problem with decrementing value with MS Access database.
I get an error
Syntax error in UPDATE Statement
My code:
connection.Open();
command = new OleDbCommand();
command.Connection = connection;
command.CommandText = " update Cards set Count = Count - 1 where Type=" + ct + " ";
command.ExecuteNonQuery();
connection.Close();
Can anyone please help?
c# sql ms-access
marked as duplicate by LarsTech
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 13 '18 at 17:20
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
what is theType
datatype?
– Ashkan Mobayen Khiabani
Nov 13 '18 at 17:02
Use parameters to avoid sql injection and to fix your problem.
– LarsTech
Nov 13 '18 at 17:03
The Type is text
– Omar
Nov 13 '18 at 17:07
parameters not solving the problem I tried
– Omar
Nov 13 '18 at 17:21
1
@themehio Stop it. Parameters is the only "safe way" to fix this mistake. If you submit code like that at a job interview, you aren't getting the job.
– LarsTech
Nov 13 '18 at 17:29
|
show 6 more comments
This question already has an answer here:
How can I add user-supplied input to an SQL statement?
2 answers
I'm facing a problem with decrementing value with MS Access database.
I get an error
Syntax error in UPDATE Statement
My code:
connection.Open();
command = new OleDbCommand();
command.Connection = connection;
command.CommandText = " update Cards set Count = Count - 1 where Type=" + ct + " ";
command.ExecuteNonQuery();
connection.Close();
Can anyone please help?
c# sql ms-access
This question already has an answer here:
How can I add user-supplied input to an SQL statement?
2 answers
I'm facing a problem with decrementing value with MS Access database.
I get an error
Syntax error in UPDATE Statement
My code:
connection.Open();
command = new OleDbCommand();
command.Connection = connection;
command.CommandText = " update Cards set Count = Count - 1 where Type=" + ct + " ";
command.ExecuteNonQuery();
connection.Close();
Can anyone please help?
This question already has an answer here:
How can I add user-supplied input to an SQL statement?
2 answers
c# sql ms-access
c# sql ms-access
edited Nov 13 '18 at 17:16
marc_s
574k12811091256
574k12811091256
asked Nov 13 '18 at 17:00
OmarOmar
14
14
marked as duplicate by LarsTech
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 13 '18 at 17:20
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by LarsTech
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 13 '18 at 17:20
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
what is theType
datatype?
– Ashkan Mobayen Khiabani
Nov 13 '18 at 17:02
Use parameters to avoid sql injection and to fix your problem.
– LarsTech
Nov 13 '18 at 17:03
The Type is text
– Omar
Nov 13 '18 at 17:07
parameters not solving the problem I tried
– Omar
Nov 13 '18 at 17:21
1
@themehio Stop it. Parameters is the only "safe way" to fix this mistake. If you submit code like that at a job interview, you aren't getting the job.
– LarsTech
Nov 13 '18 at 17:29
|
show 6 more comments
what is theType
datatype?
– Ashkan Mobayen Khiabani
Nov 13 '18 at 17:02
Use parameters to avoid sql injection and to fix your problem.
– LarsTech
Nov 13 '18 at 17:03
The Type is text
– Omar
Nov 13 '18 at 17:07
parameters not solving the problem I tried
– Omar
Nov 13 '18 at 17:21
1
@themehio Stop it. Parameters is the only "safe way" to fix this mistake. If you submit code like that at a job interview, you aren't getting the job.
– LarsTech
Nov 13 '18 at 17:29
what is the
Type
datatype?– Ashkan Mobayen Khiabani
Nov 13 '18 at 17:02
what is the
Type
datatype?– Ashkan Mobayen Khiabani
Nov 13 '18 at 17:02
Use parameters to avoid sql injection and to fix your problem.
– LarsTech
Nov 13 '18 at 17:03
Use parameters to avoid sql injection and to fix your problem.
– LarsTech
Nov 13 '18 at 17:03
The Type is text
– Omar
Nov 13 '18 at 17:07
The Type is text
– Omar
Nov 13 '18 at 17:07
parameters not solving the problem I tried
– Omar
Nov 13 '18 at 17:21
parameters not solving the problem I tried
– Omar
Nov 13 '18 at 17:21
1
1
@themehio Stop it. Parameters is the only "safe way" to fix this mistake. If you submit code like that at a job interview, you aren't getting the job.
– LarsTech
Nov 13 '18 at 17:29
@themehio Stop it. Parameters is the only "safe way" to fix this mistake. If you submit code like that at a job interview, you aren't getting the job.
– LarsTech
Nov 13 '18 at 17:29
|
show 6 more comments
2 Answers
2
active
oldest
votes
It's not certain, but I strongly suspect it's missing single quotes around ct
. Fix it like this:
using (var connection = new OleDbConnection("connection string here"))
using (var command = new OleDbCommand("update Cards set Count = Count - 1 where Type= ?", connection))
//have to guess at the OleDbType value. Use the actual column type and length from the database
cmd.Parameters.Add("?", OleDbType.VarWChar, 10).Value = ct;
connection.Open();
command.ExecuteNonQuery();
There are several other important fixes in this pattern, too.
add a comment |
You should provide an actual error.
My guess is that count is a keyword and has to be put in square brackets like so [count]
and do use parameters, see Joel's answer
count is numeric not key word
– Omar
Nov 13 '18 at 17:19
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's not certain, but I strongly suspect it's missing single quotes around ct
. Fix it like this:
using (var connection = new OleDbConnection("connection string here"))
using (var command = new OleDbCommand("update Cards set Count = Count - 1 where Type= ?", connection))
//have to guess at the OleDbType value. Use the actual column type and length from the database
cmd.Parameters.Add("?", OleDbType.VarWChar, 10).Value = ct;
connection.Open();
command.ExecuteNonQuery();
There are several other important fixes in this pattern, too.
add a comment |
It's not certain, but I strongly suspect it's missing single quotes around ct
. Fix it like this:
using (var connection = new OleDbConnection("connection string here"))
using (var command = new OleDbCommand("update Cards set Count = Count - 1 where Type= ?", connection))
//have to guess at the OleDbType value. Use the actual column type and length from the database
cmd.Parameters.Add("?", OleDbType.VarWChar, 10).Value = ct;
connection.Open();
command.ExecuteNonQuery();
There are several other important fixes in this pattern, too.
add a comment |
It's not certain, but I strongly suspect it's missing single quotes around ct
. Fix it like this:
using (var connection = new OleDbConnection("connection string here"))
using (var command = new OleDbCommand("update Cards set Count = Count - 1 where Type= ?", connection))
//have to guess at the OleDbType value. Use the actual column type and length from the database
cmd.Parameters.Add("?", OleDbType.VarWChar, 10).Value = ct;
connection.Open();
command.ExecuteNonQuery();
There are several other important fixes in this pattern, too.
It's not certain, but I strongly suspect it's missing single quotes around ct
. Fix it like this:
using (var connection = new OleDbConnection("connection string here"))
using (var command = new OleDbCommand("update Cards set Count = Count - 1 where Type= ?", connection))
//have to guess at the OleDbType value. Use the actual column type and length from the database
cmd.Parameters.Add("?", OleDbType.VarWChar, 10).Value = ct;
connection.Open();
command.ExecuteNonQuery();
There are several other important fixes in this pattern, too.
answered Nov 13 '18 at 17:05
Joel CoehoornJoel Coehoorn
307k95490721
307k95490721
add a comment |
add a comment |
You should provide an actual error.
My guess is that count is a keyword and has to be put in square brackets like so [count]
and do use parameters, see Joel's answer
count is numeric not key word
– Omar
Nov 13 '18 at 17:19
add a comment |
You should provide an actual error.
My guess is that count is a keyword and has to be put in square brackets like so [count]
and do use parameters, see Joel's answer
count is numeric not key word
– Omar
Nov 13 '18 at 17:19
add a comment |
You should provide an actual error.
My guess is that count is a keyword and has to be put in square brackets like so [count]
and do use parameters, see Joel's answer
You should provide an actual error.
My guess is that count is a keyword and has to be put in square brackets like so [count]
and do use parameters, see Joel's answer
answered Nov 13 '18 at 17:07
Daniel NDaniel N
967
967
count is numeric not key word
– Omar
Nov 13 '18 at 17:19
add a comment |
count is numeric not key word
– Omar
Nov 13 '18 at 17:19
count is numeric not key word
– Omar
Nov 13 '18 at 17:19
count is numeric not key word
– Omar
Nov 13 '18 at 17:19
add a comment |
what is the
Type
datatype?– Ashkan Mobayen Khiabani
Nov 13 '18 at 17:02
Use parameters to avoid sql injection and to fix your problem.
– LarsTech
Nov 13 '18 at 17:03
The Type is text
– Omar
Nov 13 '18 at 17:07
parameters not solving the problem I tried
– Omar
Nov 13 '18 at 17:21
1
@themehio Stop it. Parameters is the only "safe way" to fix this mistake. If you submit code like that at a job interview, you aren't getting the job.
– LarsTech
Nov 13 '18 at 17:29