本文介绍了在设置插入查询之前帮助设置计数查询计数查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个查询要向用户分配角色
I have a query to assign roles t users
MAcmd.CommandText = "INSERT INTO ROLES (UserId,GroupId) SELECT UserId,GroupId FROM Users, Groups WHERE username= '" + TextBox1.Text + "' AND rolename='" + TextBox2.Text + "'";
我想实施count sql查询,以使记录不会重复保存在
但是我不知道如何在C#中做到这一点.
例如,我找到了一个存储过程..
例如
i want to implement count sql query so that the record not repeately save in
but i don''t know how to do it in C#.
e.g i found a stored procedure..
e.g
SELECT @Count = Count(UserID) FROM UserRoles WHERE
RoleID = @RoleID AND UserID = @UserID
IF @Count = 0
INSERT INTO UserRoles(UserID, RoleID)
VALUES(@UserID, @RoleID)
谁能帮我写计数查询...如上所述,用于查询的存储过程.
can anyone help me to write count query ...as above store procedure for my query.
推荐答案
"INSERT INTO ROLES (UserId,GroupId) SELECT UserId,GroupId FROM Users, Groups WHERE username= ''" + TextBox1.Text + "'' AND rolename=''" + TextBox2.Text + "''";
仅供参考,请不要为此编写代码链接,这将在您的应用程序中创建SQL注入.请改用命令参数.
仅供参考:
SQL注入简介 [ ^ ]
FYI, Please don''t write code link this, This will create SQL Injection in your application. Use Command Parameter instead.
Just for your reference :
Introduction to SQL Injection[^]
这篇关于在设置插入查询之前帮助设置计数查询计数查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!