Click here to Skip to main content
15,557,873 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
 baglanti.Open();

OleDbCommand guncellekomutu1 = new OleDbCommand("update Malzemeler set ComponentNo='" + TxtParcaNumarasi.Text + "',Producer='" + TxtUretici.Text + "',ShelfNo='" + TxtRafNo.Text + "',BoxNo='" + TxtKutuNumarasi.Text + "',Piece='" + TxtAdet.Text + "',ProductName='" + TxtMalzemeAdi.Text + "',SerialNo='" + TxtSeriNo.Text + "',TAINo='" + TxtTAINo.Text + "',Barcode='" + TxtBarkod.Text + "',Depositary='" + TxtZimmet.Text + "',UploadDate='" + dateTimePicker1.Text + "',LastUpdateDate='" + dateTimePicker2.Text + "',LastUpdatedPerson='" + label12.Text + "',Note='" + txtnot.Text + "' where IDNo=@IDNo", baglanti);

                   
guncellekomutu1.Parameters.Add("@IDNo", OleDbType.Integer).Value = label26.Text;
guncellekomutu1.ExecuteNonQuery();
baglanti.Close();
MessageBox.Show("Material Updated!", "TUSAS SEL Warehouse Tracking Program",MessageBoxButtons.OK, MessageBoxIcon.Information);


What I have tried:

I can't solve this problem. Can somebody help? IDNo is number, others are text in access database.
Posted
Updated 7-Jul-21 4:04am

Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Fix that security vulnerability, and you'll almost certainly fix your "syntax error" problem as well.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
 
Share this answer
 
You have more serious problems to resolve.
- Never use string concatenation to build SQL commands as it can lead to the destruction of your database; always use parameterised queries.
- You are also not checking any of your inputs, so your users could write any garbage in the text boxes and your code would happily post it to the database.
- You are storing date values as strings instead of proper Date or DateTime types.
- And finally you post a success message after the update without checking whether it succeeded or not.
 
Share this answer
 
Quote:
I can't solve this problem. Can somebody help? IDNo is number, others are text in access database.

Nobody can help you because of the way you put values in your query.
C#
OleDbCommand guncellekomutu1 = new OleDbCommand("update Malzemeler set ComponentNo='" + TxtParcaNumarasi.Text + "',Producer='" + TxtUretici.Text + "',ShelfNo='" + TxtRafNo.Text + "',BoxNo='" + TxtKutuNumarasi.Text + "',Piece='" + TxtAdet.Text + "',ProductName='" + TxtMalzemeAdi.Text + "',SerialNo='" + TxtSeriNo.Text + "',TAINo='" + TxtTAINo.Text + "',Barcode='" + TxtBarkod.Text + "',Depositary='" + TxtZimmet.Text + "',UploadDate='" + dateTimePicker1.Text + "',LastUpdateDate='" + dateTimePicker2.Text + "',LastUpdatedPerson='" + label12.Text + "',Note='" + txtnot.Text + "' where IDNo=@IDNo", baglanti);

Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
 
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