String akudetaConnectionString
= "Dsn=akudetaDB;database=akudeta;description=Located at web host;option=0;port=0;server=server; uid=pass";
using (OdbcConnection con = new OdbcConnection(akudetaConnectionString))
using (OdbcCommand cmd = new OdbcCommand("UPDATE announcement SET Message =? WHERE AnnounceNo =?", con))
{
using (MySqlConnection con2 = new MySqlConnection(ConnString))
using (MySqlCommand cmd2 = new MySqlCommand("UPDATE announcement SET Message =?Message WHERE AnnounceNo =?AnnounceNo", con2))
{
cmd2.Parameters.Add("?Message", MySqlDbType.VarChar, 2000).Value = Server.HtmlEncode(FreeTextBox1.Text);
cmd2.Parameters.Add("?AnnounceNo", MySqlDbType.Int32).Value = announceID;
con2.Open();
cmd2.ExecuteNonQuery();
}
Apparently there are no errors when i put these codes in a try-catch method but my database is not updated.
all the methods you are following seems perfect, ok do one more thing, I have some doubt in your parameters. done use parameret , make it like
Dim ObjCom As MySqlCommand
ObjCom = New MySqlCommand
ObjCom.CommandType = CommandType.Text
ObjCom.CommandText = "UPDATE announcement SET Message ='"& Message.text & "' WHERE AnnounceNo=" & Annount.text
ObjCom.Connection = ObjCon
Results = ObjCom.ExecuteNonQuery
I hope this will clear the whole picture.
cheers
Dont forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
http://www.aghausman.net
Fadzuli
0 Points
2 Posts
MySQL update problem
Feb 27, 2007 01:59 PM|LINK
Hi i'm trying to update my MySQL Database and i've tried 3 methods and it did work.
Here are the codes..
1st Method - Using the object datasets - connected via ODBC
AkuDataTableAdapters.announcementTableAdapter
announceAdapter = new AkuDataTableAdapters.announcementTableAdapter();
announceAdapter.UpdateAnnouncement(DateTime.Now, Server.HtmlEncode(FreeTextBox1.Text), announceID);
2nd Method - Using ODBC connecter
String akudetaConnectionString
= "Dsn=akudetaDB;database=akudeta;description=Located at web host;option=0;port=0;server=server; uid=pass";
using (OdbcConnection con = new OdbcConnection(akudetaConnectionString))
using (OdbcCommand cmd = new OdbcCommand("UPDATE announcement SET Message =? WHERE AnnounceNo =?", con))
{
cmd.Parameters.Add("@Message", OdbcType.VarChar, 2000).Value = Server.HtmlEncode(FreeTextBox1.Text);
cmd.Parameters.Add("@AnnounceNo", OdbcType.Int).Value = announceID;
con.Open();
cmd.ExecuteNonQuery();
}
3rd method using .Net Connector
String ConnString = " Database=akudeta;Data Source=akudeta.com;";
ConnString += " User Id=akudetadb; Password=pass";
using (MySqlConnection con2 = new MySqlConnection(ConnString))
using (MySqlCommand cmd2 = new MySqlCommand("UPDATE announcement SET Message =?Message WHERE AnnounceNo =?AnnounceNo", con2))
{
cmd2.Parameters.Add("?Message", MySqlDbType.VarChar, 2000).Value = Server.HtmlEncode(FreeTextBox1.Text);
cmd2.Parameters.Add("?AnnounceNo", MySqlDbType.Int32).Value = announceID;
con2.Open();
cmd2.ExecuteNonQuery();
}
Apparently there are no errors when i put these codes in a try-catch method but my database is not updated.
Any help would be greatly appreciated. Thank You.
aghausman12
Contributor
3035 Points
550 Posts
Re: MySQL update problem
Feb 28, 2007 10:05 AM|LINK
Hi,
all the methods you are following seems perfect, ok do one more thing, I have some doubt in your parameters. done use parameret , make it like
I hope this will clear the whole picture.
cheers
http://www.aghausman.net
Fadzuli
0 Points
2 Posts
Re: MySQL update problem
Feb 28, 2007 01:33 PM|LINK
Hi,
I tried as what you said..
I'm using C# and so the little difference here.
String ConnString = " Database=akudeta;Data Source=akudeta.com;";
ConnString += " User Id=akudetadb; Password=pass";
MySqlCommand cmd2 = new MySqlCommand();
MySqlConnection con2 = new MySqlConnection(ConnString);
cmd2.CommandType = CommandType.Text;
cmd2.CommandText = "UPDATE announcement SET Message ='" + Server.HtmlEncode(FreeTextBox1.Text) + "' WHERE AnnounceNo='" + announceID.ToString() +"'";
cmd2.Connection = con2;
con2.Open();
int i = cmd2.ExecuteNonQuery();
con2.Close();
Error.Text = i.ToString();
The i returns 0 which also means that it did not update the table.
Anway i deleted the table and recreate it again. Still no changes. But updates for other tables are working fine...Just this one...haizz..