如何使用C#varchar数据类型? [英] How to use the varchar data type in c#?
问题描述
我有这样的一段代码,我想使它VARCHAR不串。什么是适当的语法做,在C#
字符串emri =行[诺姆]的ToString()。
我有一个查询,我必须跑,我在使用它emri并与一列比较表,其中我在mysql中创建。在MySQL中列类型为varchar(20)。当我执行我的代码它给出了一个错误在我的查询,我猜也许是因为这个原因。
我有这个疑问
查询字符串=IF NOT EXISTS(SELECT * FROM clienti WHERE CodCliente =+编号+和诺姆='+ emri +'AND RagioneSociale ='+ ragSoc +'AND PartitaIVA ='+皮瓦+')INSERT INTO clienti VALUES(+编号+,'+ emri +,+ ragSoc +,+皮瓦+'),否则UPDATE clienti SET(+编号+ '+ emri +,+ ragSoc +,+皮瓦+');
和它给了我这个问题。
你在你的SQL语法错误;检查对应于你的MySQL服务器版本使用附近的正确语法手册IF NOT EXISTS(SELECT * FROM clienti WHERE CodCliente = 1 AND NomeCliente ='乔'在行1
有没有 VARCHAR
键入C#。
A VARCHAR
几乎是一个字符串(可变长度的SQL,很明显),所以你有什么是好的
I have this piece of code and I want to make it varchar not string. What is the appropriate syntax to do that in c#
string emri = row["Nome"].ToString();
I have a query that I have to run and I use emri in it and compare it with a column in table which I have created in mysql. the column in mysql is of type varchar(20). When I execute my code it gives an error in my query and I was guessing maybe it was for this reason
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 + " ')";
and it gives me this problem
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
There is no varchar
type in C#.
A varchar
is pretty much a string (of variable length in SQL, obviously), so what you have is fine.
这篇关于如何使用C#varchar数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!