0
我試圖插入數據到sql server varchar(max)字段並保留換行符。這些是地址,換行符對解析地址數據至關重要。我運行的輸出窗口,看看有什麼結果都和換行符保持在命令行,但不是插入到SQL Server保留CR LF(新行)插入到SQL Server
for dirpath, subdirs, files in os.walk(process):
for file in files:
dateadded = datetime.datetime.now()
if file.endswith(('.dbf', '.DBF')):
dbflocation = os.path.abspath(os.path.join(dirpath, file)).lower()
if dbflocation.__contains__("\\xxx.dbf"):
table = DBF(dbflocation, lowernames=True, char_decode_errors='ignore')
for record in table.records or table.deleted:
rec1 = record['key1']
rec2 = str(record['xxx1'])
rec3 = str(record['xxx2'])
rec4 = record['xxx3']
rec5 = str(record['xxx4'])
rec6 = record['address1'] #address to parse
# if table.delete == True:
# rec42 = 1
cursor.execute(
"insert into tblepiqclaims(key1,xxx1,xxx2,xxx3,xxx4,address1) values(?,?,?,?,?,?)",
rec1, rec2, rec3, rec4, rec5, rec6)
print rec6
cnxn.commit()
如果通過在SQL Server Management Studio中打開它檢查表( SSMS),那麼它可能會欺騙你。 SSMS不在標準網格視圖中顯示換行符。你可以使用'CONVERT(VARBINARY,address1)'來查看該值是否包含'0D0A'(用於VARCHAR)或'0D000A00'(用於NVARCHAR)來驗證CR_LF換行符是否真的存在。 –