c# - 如何在c#中使用varchar数据类型?

标签 c#

我有这段代码,我想让它变成 varchar 而不是 string。在 c# 中执行此操作的适当语法是什么

 string emri = row["Nome"].ToString();

我有一个必须运行的查询,我在其中使用 emri 并将其与我在 mysql 中创建的表中的列进行比较。 mysql 中的列是 varchar(20) 类型。当我执行我的代码时,它在我的查询中给出了一个错误,我猜可能是因为这个原因

I have this query 
string query = "IF NOT EXISTS(SELECT * FROM clienti WHERE CodCliente=   " + id + "  AND Nome = '" + emri + "' AND RagioneSociale=' " + ragSoc + " ' AND PartitaIVA=' " + piva + " ') INSERT INTO clienti VALUES(" + id + " ,' " + emri + " ',' " + ragSoc + " ',' " + piva + " ') else UPDATE clienti SET( " + id + " ,' " + emri + " ',' " + ragSoc + " ',' " + piva + " ')";

它给了我这个问题

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS(SELECT * FROM clienti WHERE CodCliente=   1  AND NomeCliente = 'Jo' at line 1

最佳答案

C#中没有varchar类型。

varchar 几乎是一个字符串(在 SQL 中显然是可变长度的),所以您拥有的就可以了。

关于c# - 如何在c#中使用varchar数据类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16112982/

相关文章:

c# - 使用名称中的参数调用函数

c# - 在子对话框中获取 LUIS 实体

c# - silverlight TypeDescriptor.GetConverter 替代品

C# JSON反序列化: can I intercept the deserialization and optionally change the result?

c# - 如何在 LINQ 查询中使用 SQL Server 时钟

c# - 多个 DbContext 会产生死锁吗?

c# - 文件未找到异常 : Could not load

c# - 如何将 A<T> 类型的泛型对象转换为 A<T'>?

c# - 这个并行异步调用可以简化吗?

c# - ComponentOne WPF RichTextBox 未正确处理 AddPastingHandler 或 AddCopyingHandler