LIKE命令Mysql [英] LIKE command Mysql

查看:69
本文介绍了LIKE命令Mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我此命令有什么问题吗?我得到一个错误.我使用c#和mysql数据库.

Can someone tell me what is wrong with this like command? I get an error. I use c# and mysql database.

 public static DataSet getInstructorListSearchEmail(string instemail)
        {
            DB.connectToDb();
            DB.DBOpen();

        DataSet ds = new DataSet();
        try
        {
            string comText = "select * from instructor where Instructor_email like %instemail";
            MySqlCommand com = new MySqlCommand(comText, DB.Conn);
            com.Parameters.Add("instemail", MySqlDbType.VarChar, 200).Value = instemail;
            MySqlDataAdapter adapter = new MySqlDataAdapter(com);
            adapter.Fill(ds);

推荐答案

现在看到您使用了cmd参数,您需要通过将查询字符串更改为类似

Seeing now you used a cmd parameter you need to modify your query string to accept parameters by changing it to something like

string comText = "select * from instructor where Instructor_email like @instemail";
com.Parameters.AddWithValue("@instemail", "%" + instemail);

或者使用单引号并删除参数也可以,但是我认为使用参数会更好.

or this would work as well using single quotes and drop the parameter but I think using parameters are better.

string comText = "select * from instructor where Instructor_email like '%" + instemail + "'";

这篇关于LIKE命令Mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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