DML操作不起作用. [英] DML operation is not working.

查看:99
本文介绍了DML操作不起作用.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,


我正在使用Asp.net c#和MYSql作为后端.

我正在更新表,但表没有更新.表中只有3列.
我执行命令对象时也不例外.但是这将从cmd.ExecuteNonQuery()返回0值.
我对此进行了调试,发现 cmd.Parameters 充满了值.
如果我在mysql中手动运行更新命令,它将正常工作.

表格如下
列-数据类型
ShortText-varchar
标题-varchar
id-int

请指导我...

Hello Friends,


I''m using Asp.net c# and MYSql as back-end.

I''m updating a table,but table is not updating.There are only 3 columns in the table.
There is no exception when I''m executing the command object. But this returns 0 value from cmd.ExecuteNonQuery().
I debugged this and found cmd.Parameters are full with values.
and if i manually run the update command in mysql it works fine.

the table is as follow
column -- Datatype
ShortText -- varchar
title -- varchar
id -- int

Please guide me...

int retVal = 0;
        string shortText = ((TextBox)fmvwShortText.FindControl("txtShortText")).Text.Trim();
        try
        {
            int id = Convert.ToInt32(((Label)fmvwShortText.FindControl("lblShrtTextID")).Text);
            MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.AppSettings["conn"]);
            cmd = new MySqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "UPDATE temp_posts SET ShortText=@shrtText WHERE id=@id AND Title=@title";
            cmd.Parameters.Add("@shrtText", MySqlDbType.VarChar).Value = shortText;
            cmd.Parameters.Add("@title", MySqlDbType.VarChar).Value =Session["EditTitle"].ToString();
            cmd.Parameters.Add("@id", MySqlDbType.Int32).Value = id;
            con.Open();
            retVal = cmd.ExecuteNonQuery();
            con.Close();
        }
        catch (Exception e) { }
        return retVal;



谢谢.



Thanks.

推荐答案

报价:

这从cmd.ExecuteNonQuery(返回0值. ).

this returns 0 value from cmd.ExecuteNonQuery().





cmd.ExecuteNonQuery()


返回更新表后受影响的记录数.由于您的输出为0,表示执行查询后受影响的行数为0.

您必须主要在Where子句中检查Update查询


returns number of records affected after updating the table. As your output is 0 means 0 number of rows affected after execution of the query.

You must check your Update query in Where clause mainly
in

Session["EditTitle"].ToString();

中,因为这是一个varchar,它的空格可能与您的可用记录不同.

because this is a varchar it may have spaces which may differ form your available records.


您好,
看来您的字体结尾没有给出任何错误.错误是来自sql表或数据库本身.尝试使用 sql-profiler [ ^ ].

这将帮助您找到解决方案.
祝一切顺利.
--Amit
Hi,
It seems that your font-end is not giving any error. The error is from sql table or database itself. Try tracing the query which you are passing from front-end using sql-profiler[^].

This will help you to find your solution.
All the best.
--Amit


这里最简单的方法是在cmd.ExecuteNonQuery()上放置一个断点.
提取查询并将其粘贴到SQL Management Studio中.

放置适当的参数,然后运行查询.
这将使您了解查询可能出了什么问题.
The easiest approach for you here is to put a breakpoint on cmd.ExecuteNonQuery().
Pick up the query and paste it in SQL Management studio.

Put appropriate parameters and then run the query.
This would give you an idea of what could be going wrong with the query.


这篇关于DML操作不起作用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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