检查mysql db中是否已存在 [英] Check if already exist in mysql db

查看:97
本文介绍了检查mysql db中是否已存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我想检查我的表中是否已经存在文本如果存在不插入且如果不存在则插入它



i write命令只是为了插入我不知道在插入之前如何检查



hi guys i want to check if text already exist in my table if exist don't insert and if doesn't exist insert it

i wrote command just to insert i don't know how to check before inserting

MySqlConnection conect = new MySqlConnection(connectionString);
                conect.Open();
                MySqlCommand cmsd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                lochwidTxt.Text = HWDI.GetMachineGuid();
                cmd.CommandText = "INSERT INTO userprof  (u_name, u_pass, u_ip) " + " Values ('" + textBox1.Text + "', '" + textBox2.Text + "', '" + lochwidTxt.Text + "')";





我尝试过:



检查是否已存在(如果它不存在)插入



What I have tried:

check if already exist if it doesn't exist insert it

推荐答案

永远不要通过连接用户输入来构建SQL查询,它被命名SQL注入,它对您的数据库很容易并且容易出错。

名称中的单引号和程序崩溃。如果像Brian O'Conner这样的用户输入可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞。

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]
Never build an SQL query by concatenating with user inputs, it is named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability.
SQL injection - Wikipedia[^]
SQL Injection[^]


这篇关于检查mysql db中是否已存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆