mysql之返回影响行数

mysql更新数据,这里我提出一个问题:

当mysql更新的时候,这一条数据已经被删除了?那怎么办?会提示更新失败吗?

现在开始现场实验

ExecuteNonQuery 这个函数可以返回影响的行数,如果返回影响行数为0,表示没有这个数据,返回大于0为影响函数

            DBMysql dBMysql = new DBMysql();
            dBMysql.ConnectDB("10.10.13.140", 3306, "root", "sa", "testdb");

            string strSql = "update  recordpiece set status =9  where id in (1)"; //
            if (!dBMysql.SqlExe(strSql))
            {
                Console.WriteLine("SupplyFreeBlock m_bFileFull = false error sql ={0}", strSql);
                return;
            }

输出:

 修改一下值:

            DBMysql dBMysql = new DBMysql();
            dBMysql.ConnectDB("10.10.13.140", 3306, "root", "sa", "testdb");

            string strSql = "update  recordpiece set status =9  where id in (7,8,9)"; //
            if (!dBMysql.SqlExe(strSql))
            {
                Console.WriteLine("SupplyFreeBlock m_bFileFull = false error sql ={0}", strSql);
                return;
            }

输出:

执行数据库的插入的时候,同样可以返回影响的行数:

            DBMysql dBMysql = new DBMysql();
            dBMysql.ConnectDB("10.10.13.140", 3306, "root", "sa", "testdb");

            string strdata = "('C:/Users/shenwei/Desktop/tool/tool/csharp/ArrayInit/ArrayInit/Properties/1.test',60000000,1,1)";
            string strSql = "insert into  recordpiece(path,size, status,recordlun) values ('C:/Users/shenwei/Desktop/tool/tool/csharp/ArrayInit/ArrayInit/Pr',555,10,1)"; //
            strSql = strSql + "," + strdata;
            if (!dBMysql.SqlExe(strSql))
            {
                Console.WriteLine("SupplyFreeBlock m_bFileFull = false error sql ={0}", strSql);
                return;
            }

输出两行:

猜你喜欢

转载自blog.csdn.net/g0415shenw/article/details/88178531