gpt4 book ai didi

c# - 尝试通过 ASP.NET 中的命令文本在 SQL Server 2014 中插入 ' Rahul' s Sister 时出错

转载 作者:太空宇宙 更新时间:2023-11-03 22:44:07 24 4
gpt4 key购买 nike

<分区>

我试图将给定的字符串插入到我的表 table1 中,但出现错误

Incorrect syntax near s

如果我传递像“rahul s sister”这样的字符串作为输入,它运行良好,但在尝试传递“Rahul's sister”时抛出错误。

请告诉我应该怎么做?

String str = "Rahul's Sister"
cmd.Connection = con;

con.Open();

cmd.CommandText = "insert into table1(relation_n) values(N'"+str+"')";
con.Close();

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com