问题描述
你好朋友,
我正在使用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.
这篇关于DML操作不起作用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!