在表中插入唯一数据 [英] insert unique data in table
本文介绍了在表中插入唯一数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
cmd.CommandText = "insert into " + table + " values ('" + textBox1.Text + "', '" + textBox2.Text + "') where not exists(select * from " + table + " where character='" + textBox1.Text + "' and entity='" + textBox2.Text + "');";
i想在我的表中插入唯一数据而我是越来越此查询中的错误(其中的语法不正确)...
i want to insert unique data in my table and i'm getting error in this query (Incorrect syntax near where)...
推荐答案
T-SQL不允许在该位置使用where子句。请参阅此处: http://msdn.microsoft.com/de-de/library/ms174335.aspx [ ^ ]
干杯!
T-SQL does not allow for a where clause in that place. See here: http://msdn.microsoft.com/de-de/library/ms174335.aspx[^]
Cheers!
您好,
请尝试以下查询。
Hi,
Try following query.
cmd.CommandText = "if not exists (select * from " + table + " where character='" + textBox1.Text + "' and entity='" + textBox2.Text + "') insert into " + table + " values ('" + textBox1.Text + "', '" + textBox2.Text + "') where not exists";
谢谢,
Bhagyesh
Thanks,
Bhagyesh
这篇关于在表中插入唯一数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文