Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
137 views
in Technique[技术] by (71.8m points)

sql - what do i write into c# to edit the data in an access database

I have an access database that I created using sql in the actual program and have used a 'BIT' to make a record true or false. Now I would like to use the update sql statement to change whether my record is true or false.

For example I have a payments database table and a paid record which is either true or false.

if (HasPaidCBOX.Checked)
{
    Cmd.CommandText = "UPDATE Payments SET Paid = @p WHERE PlayerID ='" + PaymentForm.ID + "'";
    Cmd.Parameters.AddWithValue("@p", xxx);
    Cmd.ExecuteNonQuery();
}

I would like to know what goes in the place marked with three x's.

question from:https://stackoverflow.com/questions/65598237/what-do-i-write-into-c-sharp-to-edit-the-data-in-an-access-database

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Access uses -1 for TRUE and 0 for FALSE. So use 0 and -1.

Also, as pointet out by @ADyson you should parameterise all values in your SQL statements.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...