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;
First of all thank you every one who kept looking and tried their best to sort out this problem with me..
Finally got the solution.
In my code I used @ in cmd.CommandText and in parameters.
But when I replace this @ with ? both in cmd.CommandText and in parameters and used the cmd.ExecuteScalar(); this worked.
Actually Parameter names depend on the provider. When using the provider for
SQL Server, it should start with @ (e.g. @param1). For Oracle
provider, it should start with a colon (…for e.g. aram1. For
OleDb provider, just a question mark (?) would work
Thank you everyone to contribute your best… many thanks
But i’m still left with a question that ExecuteScalar() is updating the records in the database? I am with no answer… looking for this.