I need help trying to do an Insert statement based on a serial number match. The field in the table “EDI40025.Bundle_Serial_Num” is 20 chars long, and the “SerialNumber.Text” that is 6 chars. Can I somehow take the substring of the Bundle_Serial_Num so that I only check 6 chars so that it will match the text field?
For example my Bundle_Serial_Num is "UNS40000000000447022" and the SerialNumber.Text is "447022". I want to compare the last 6 of the Bundle_Serial_Num with the 6 from the text field.
string sql = @"INSERT INTO EDI40021 (Vendor_Order, BOL_Num, Cust_Part_Num)
WHERE (EDI40025.Bundle_Serial_Num = '" + SerialNumber.Text + "')";
Thank you.
Use the
RIGHTfunction to grab the last six characters of the serial number.However, you most likely want to re-write your query as a parametrized query if possible as you are currently vulnerable to SQL injection attacks.
Also, your query doesn’t quite look right, because you’re not
SELECTINGfrom table EDI40025.