Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
con.Open();
command = new OleDbCommand("select * from Instructor where insno=? AND inclass=?", con);
command.Parameters.Add("@insno", OleDbType.VarChar).Value=txtid.Text;
command.Parameters.Add("@inclass", OleDbType.Boolean).Value=false;
adapter.SelectCommand = command;
OleDbDataReader reader = command.ExecuteReader();
if (reader.Read() == true)
{
    command = new OleDbCommand("UPDATE Instructor SET inclass = ? WHERE insno=?", con);
    command.Parameters.Add("@insno", OleDbType.VarChar).Value = txtid.Text;
    command.Parameters.Add("@inclass", OleDbType.Boolean).Value = false;
    adapter.UpdateCommand = command;
    adapter.UpdateCommand.ExecuteNonQuery();
{
    MessageBox.Show("!!!!!");
}
con.Close();
Posted
Updated 13-Dec-14 20:58pm
v2

Your order of parameter declaration is incorrect. Otherwise code looks good. According to the query, inclass parameter should come first and then insno.
C#
command = new OleDbCommand("UPDATE Instructor SET inclass = ? WHERE insno=?", con);
    
command.Parameters.Add("@inclass", OleDbType.Boolean).Value = false;
command.Parameters.Add("@insno", OleDbType.VarChar).Value = txtid.Text;
 
Share this answer
 
Comments
markqui 15-Dec-14 2:53am    
thank you
Most welcome. :)
I think you can do the update at one execution
C#
con.Open();
bool inclass =false; // set this value true or false 
var command1 = new OleDbCommand("UPDATE Instructor SET inclass = ? WHERE inclass = ? and insno=?", con);
// above line ~inclass will set the invert value of current inclss value if the where condition match 
command1.Parameters.AddWithValue("?", !inclass); 
command1.Parameters.AddWithValue("?", inclass); 
command1.Parameters.AddWithValue("?", txtid.Text);
int rowcount =command1.ExecuteNonQuery(); // if rowcount > 0 means update success 
con.Close();
 
Share this answer
 
v3
Comments
markqui 14-Dec-14 3:41am    
having trouble with line 4, "inclass" does not exist in the current context.
DamithSL 14-Dec-14 3:43am    
you can give false, check my updated answer, you can pass this value to your function/method.
markqui 14-Dec-14 3:54am    
ok i did! but another error.."syntax error with ~inclass.
markqui 14-Dec-14 4:03am    
syntax error in query expression "~inclass"
DamithSL 14-Dec-14 4:16am    
Ok, answer updated, please check
Please see my past answers[^]. I suggest to use named parameters.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900