SEARCH YOUR SOLUTION HERE  

MySQL update problem

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.

Posted On: Wednesday 21st of November 2012 02:06:59 AM Total Views:  224
View Complete with Replies




Related Messages:

How to do dropdownlist search in asp.net with C# with mysql ?   (264 Views)
I got table name ( customer ) and field Name as ( customerId , companyName , personName and poscode ) in Mysql Now i have created search function by using textbox (txtCompanyName.Text) like where i can query companyName by entering data to textbox to search . Coding :- qry = "select * from customer where companyName='" + txtCompanyName.Text + "'"; Bt i want to do search by using1 dropdownlist(companyName , personName, poscode).For example i selectdropdownlist as companyName andenter thename in textbox and search. After that i select the same dropdownlist with personName field and enter the name of the person and search . How to do that and what is the mysql query for such case Please help .
How to store and reterive the Image using mysql   (181 Views)
Hi I am developing the project in C# . i have store the image to the mysql database and reterive the image inAsp.net if any one know please help me...
mysql connector/Net   (173 Views)
I read throug about mysql connector. I get unclear point in this fact : Large-packet support for sending and receiving rows and BLOBs up to 2 gigabytes in size. It means that connector could handle up to 2 gigabytes size of a row with BLOB, is it
How to learn mysql.   (143 Views)
How can i learn mysql. i learn something something from ebooks but how i can run our mysqlcommand in asp.net mysql apps
mysql data source   (113 Views)
can anybody make heads or tales of the following nnection = New OdbcConnection("Driver={mySQL};Server=XXXXXXXX;Option=0000;Stmt=;Database=XXXXX; User=xxxxx;Password=xxxxx;") Line 25: Dim cmdstring As String = "SELECT clientnumber FROM clients WHERE clientnumber ='" & clientnumber & "'" Line 26: strconnection.Open() Line 27: Line 28: CMD = New OdbcCommand(cmdstring, strconnection) Exception Details: System.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ORIGINAL CODE BELOW strconnection = New OdbcConnection("Driver={mySQL};Server=XXXXXXXX;Option=3306;Stmt=;Database=XXXXX; User=xxxxx;Password=xxxxx;") Dim cmdstring As String = "SELECT clientnumber FROM clients WHERE clientnumber ='" & clientnumber & "'" strconnection.Open() any help is apreciated
Connecting to mysql localhost   (125 Views)
I just used part 1 and part 2 of this tutorial and I did all the installation/configuration, but when I try to run my page, I get the following error: I cannot find any resolution, anyone thanks. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) Type of Property namespace DataAccess { public class DataReader { public static DataSet GetPropertyTypes() { string connectionString = "server=localhost; user id=Developer; password=mypassword; database=mydatabase; pooling=false;"; SqlConnection sqlConnection = new SqlConnection(connectionString); string queryString = "select * From propertytypes order by propertytypedescription"; SqlDataAdapter dataAdapter = new SqlDataAdapter(queryString, sqlConnection); DataSet dsPropertyTypes = new DataSet(); dataAdapter.Fill(dsPropertyTypes); return dsPropertyTypes; } } }
validating username and password in asp.net using mysql   (221 Views)
Hi , I am new to asp.net and MySQL . I am using MySQL 5.1 . I have a login form where username and password is entered into a textbox . The validation is done against the 'Username' and 'Password' fields in 'new' table which is in 'password' schema . serverhost :localhost uid:root password:pwd 1) vallidation should be done 2) if successful , it should redirect to 'Home.aspx' 3) else it should redirect to 'invalid.aspx' Can some one write the code for me
Too many connections error in mysql   (273 Views)
i am getting this error 'System.Data.Odbc.OdbcException: ERROR [HY000] [MySQL][ODBC 3.51 Driver]Too many connections.' from the asp.net site. Database server is on another machine. i am closing all connections as soon as a database ttransaction gets over. I have given option=3;Pooling = true;Min Pool Size=5;Max Pool Size=60;Connect Timeout=0; in the connection string what may be the problem
Question about mysql migration   (244 Views)
I'm thinking about migrating my MS SQL driven web project to mysql. In my project I use formview with edit/update field functions. Will this work in mysql, Can I use the same code ( I know I will have to change the connection string)
Splitting varchar in stored procedure using mysql   (192 Views)
Hi. I would liketo know if there is amethod to split a varchar in stored procedure Or i can only split the varchar using algorithm
mysql connector auto update command specifies incorrect database need another way to update   (242 Views)
I use Typed Datasets for my DAL and class files for my BLL The Application uses multiple databases depending on what user logs in. The MSSQL autogenerated update method uses a sort of agnostic database variable [dbo]. so when the app passes in a different dabase name in its connection string it updates the correct database. However the MYSQL autogenerated code for the update command actually specifies the name of the dabase that the tableadapter is using when you create the typed dataset. so even if you pass in a different database in the connection string...it still goes to the original database name. This is how I currently update rows in a database in my BLL using System; using System.Data; using System.Configuration; using System.Web; using VinWinBLL.DAL.CONTACTDAL.CompanyDALTableAdapters; using VinWinBLL.DAL.CONTACTDAL; namespace VinWinBLL.BLL.CONTACTBLL { /// /// Summary description for CompanyBLL /// public class CompanyBLL { private tblcompanyTableAdapter _tblcompanyAdapter = null;internal tblcompanyTableAdapter CompanyAdapter { get { if (_tblcompanyAdapter == null) _tblcompanyAdapter = new tblcompanyTableAdapter(); return _tblcompanyAdapter; } } public bool UpdateCompany(long companyid, string company, bool active) { CompanyDAL.tblcompanyDataTable companies = CompanyAdapter.GetCompanyDataByCompanyID(companyid.Value);if (companies.Count == 0) { return false; } CompanyDAL.tblcompanyRow comp = companies[0]; comp.Active = active; comp.Company = company; int rowsAffected = CompanyAdapter.Update(comp);return rowsAffected == 1; } I apparently need another way to handle this since the autogenerated code using teh mysql connector has this bug. I am thinkingof adding a query in the tableadapter to "Update" the databale. I do this with the insert and it works properly making use of the connection string databse name. Mainly because the sql statement doesnt specify the database name like the autogenerated methods do. For example the autogenerated insert this._adapter.InsertCommand.CommandText = "INSERT INTO `vinwin_base_dbo`.`tblcompany` (`Company`, `Active`) VALUES (@Company" + ", @Active)"; My added insert methods sql statement this._commandCollection[5].CommandText = "INSERT INTO tblcompany\r\n (Company, Active)\r\nVALUES (@Com" + "pany, @Active);\r\nSelect last_insert_id();\r\n"; Notice how my sql statement doesnt specify the database name. To access the insert I use the following in my BLL class file private tblcompanyTableAdapter _tblcompanyAdapter = null;internal tblcompanyTableAdapter CompanyAdapter { get { if (_tblcompanyAdapter == null) _tblcompanyAdapter = new tblcompanyTableAdapter(); return _tblcompanyAdapter; } } public long AddCompany(string company, bool active) { byte b_active = Convert.ToByte(active); long companyid = Convert.ToInt64(CompanyAdapter.InsertQuery(company, b_active)); return companyid; } So what I am wondering is if I create in teh table adapater an update method so that it looks like this this._commandCollection[6].CommandText = @"UPDATE tblcompany SET Company = @Company, Active = @Active WHERE (CompanyID = @Original_CompanyID) AND (@IsNull_Company = 1) AND (Company IS NULL) AND (Active = @Original_Active) OR (CompanyID = @Original_CompanyID) AND (Company = @Original_Company) AND (Active = @Original_Active)"; Problem is I am not sure how to handle this in the BLL. If I try to handle it in the same manner using the new "UpdateQuery" methodI get a build error No Overload for Method UpdateQuery takes 1 argument.
mysql, C# and vwd 2008 connection problem   (308 Views)
I have tried for weeks to get this right but am unable to do so .. 1) I downloaded Mysql connector 5.2.2. and Visual Web developer 2008 I added the necessary code changes to web.config and placed the Mysql.dll file in .Net directory. I added the reference to it in my project. I also added the necessary code to machine.config as well, to handle the Mysql stuff... I went into the administrator for ASP.NET and selected Mysql for the DB ... I cannot see the DB in the database explorer. Why cant i see it It only gives me options for ODBC, SQL SERVER, etc .. but not MySQL. I require this to make it easier for me to access the DB and output data. Also, can one show me how to 1)physically connect to the mysql DB in C# 2) Run an SQL statement in C# and output the results in a table/grid/form when the user clicks on a button(using visual web developer) 3) Assign variables to the result of an SQL statement.. Eg select user_name, user_password from users String g_user_name = user_name String g_user_password = user_password Please, your help will be really apprecaited. I have tried fortoo long with0 success ...
wait_timeot in mysql   (157 Views)
How can i change l "wait_timeout" in mysql. I tried the command "set @@wait_timeout=30" but when my sql restarted, it again change to 28800. I am using windows XP and mysql 5.0
mysql connector .net terminate my database   (208 Views)
hi recently i have started using mysql connector .net 5.0.5 for my application,whenitestingtheapplicationatmylocalhostit'sworkfine. but when i upload to the server the system have terminate my database after i review my application. below is the error i get Exception of type 'System.Exception' was thrown. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Exception: Exception of type 'System.Exception' was thrown. Source Error: Line 24: Line 25: Using (con) Line 26: con.Open() Line 27: Dim reader As MySqlDataReader = cmd.ExecuteReader() Line 28: While reader.Read() [Exception: Exception of type 'System.Exception' was thrown.] MySql.Data.MySqlClient.NativeDriver.Open() +521 [MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.] MySql.Data.MySqlClient.NativeDriver.Open() +606 MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) +94 MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() +30 MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() +61 MySql.Data.MySqlClient.MySqlPool.GetConnection() +202 MySql.Data.MySqlClient.MySqlConnection.Open() +359 configDAL.SelectField(String field) in C:\Domains\wwwroot\demo\App_Code\DAL\configDAL.vb:26 configBLL.SelectField(String field) in C:\Domains\wwwroot\demo\App_Code\BLL\configBLL.vb:29 _default.Page_Load(Object sender, EventArgs e) in C:\Domains\wwwroot\demo\default.aspx.vb:10 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061 can i know what is the reason
write data to mysql from an example using sql server   (226 Views)
i have problems getting the data into my mysql database. its probably somewhere in this file. because if i dont use it, no error occurs. i got this code from an example in a book, the book was using sqlserver, so i guess maybe i need to change some commands to fit with mysql instead. but i have no idea which ones, can anyone help me please ImportsMicrosoft.VisualBasic 'ImportsSystem.Data.SqlClient ImportsSystem.Data.Odbc ImportsSystem.Web.Configuration Public Class OrderDB Shared tran As OdbcTransaction Shared con As OdbcConnection Public Shared Function WriteOrder(ByVal o As Order) As Boolean Dim cs As String cs = WebConfigurationManager.ConnectionStrings("FM").ConnectionString con = New OdbcConnection(cs) con.Open() tran = con.BeginTransaction() Try ' InsertCustomer(o.Cust) Dim oNum As Integer oNum = InsertOrder(o) For Each item As CartItem _ In o.Cart.GetItems() InsertItem(item, oNum) Next tran.Commit() con.Close() Return True Catch ex As Exception tran.Rollback() Return False End Try End Function Private Shared Function InsertOrder(ByVal o As Order) As Integer Dim cmd As New OdbcCommand() cmd.Connection = con cmd.Transaction = tran cmd.CommandText = "INSERT INTO bestallningshuvud (Betalning) VALUES (6)" 'cmd.Parameters.AddWithValue("", DateTime.Now) 'cmd.Parameters.AddWithValue("", "Faktura") 'cmd.Parameters.AddWithValue("", "o.SubTotal") cmd.ExecuteNonQuery() cmd.CommandText = "SELECT @@IDENTITY" Return True Return Convert.ToInt32(cmd.ExecuteScalar()) End Function Private Shared Sub InsertItem(ByVal item As CartItem, ByVal oNum As Integer) Dim cmd As New OdbcCommand() cmd.Connection = con cmd.Transaction = tran cmd.CommandText = "INSERT INTO bestallningstyp (Artnr, Antal, OrderId, Total, Pris)VALUES (11, 2, 12, 23, 22)" '''' cmd.Parameters.AddWithValue("", item.ID) '''' cmd.Parameters.AddWithValue("", oNum) '''' cmd.Parameters.AddWithValue("", item.Quantity) '''' cmd.Parameters.AddWithValue("", item.Name) '''' cmd.Parameters.AddWithValue("", item.Price) cmd.ExecuteNonQuery() End Sub End Class
check a single mysql field for a certain value   (153 Views)
I am trying to check a particular MySQL field in ASP.NET 1.1. The field contains a single character, "y" or "n" are the 2 possible values. I want to send a user to one of 2 pages depending on the value of that field. How can I do this in ASP.NET 1.1 My best attempt is below: Please note that some variables below are defined in earlier parts of the script, so I know the only problem is my syntax as it concerns the database stuff... Dim strSQL As String Dim datNow As DateTime = Now() Dim strNow As String = datNow.ToString("yyyy-MM-dd HH:mm:ss") Dim myConnection As String = ConfigurationSettings.AppSettings("ConnectionString") strSQL = "SELECT page1 FROM table WHERE customer_id = '" & CustID & "';" Dim con As New MySqlConnection(myConnection) Dim cmd As New MySqlCommand(strSQL, con) con.Open() Dim reader As MySqlDataReader = cmd.ExecuteReader() Do While reader.Read() Dim page1 As String = reader("page1") Loop If page1 Is "n" Then...
how to create the dsn for a database in mysql   (189 Views)
hi, how to create the dsn for a database in my sql and where wil be the account manger and my products list in my sql Ramesh
displaying a mysql table in formview   (235 Views)
, I have recently migrated all of my databases from ms sql server express 2005, to MySQL, as most web host do not provide the vast quantity of ms sql server space that i am going to need for my website. So far, everything is going fine. I migrated the databases, and i even got MySQL to work with visual web developer express 2005. However, i am currently facing some difficulties in displaying and entering some data into the MySQL database. Now, what im trying to do is that, when the user opens the sharedownloads.aspx page, the database verifies the user's username, and displays the files that corresponds to the user's username, in the formview control And this is the c# code protected void Page_Load(object sender, EventArgs e) { if ( !Page.IsPostBack) { SqlDataSource2.SelectParameters["UserName"].DefaultValue = User.Identity.Name; showDbImage(); } } Now, when i run the page, nothing is displayed in the formview, and i have no idea why. I am sure that the code works, because, at the end of the sql statement, when i remove ' WHERE (UserName = @Username), then all the files are shown in the formview.
mysql connection   (367 Views)
iam using mysql database and my code is Imports System Imports System.Data Imports System.Data.odbc Imports System.Configuration Partial Class _Default Inherits System.Web.UI.Page Dim strConStr As String Dim da As OdbcDataAdapter Dim ds As New DataSet Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim strConn As String strConn = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=test; UID=mysql_username; PASSWORD=pcs; OPTION=3" Dim MyConn As New OdbcConnection(strConn) Dim MySQL As String = "Select * from test" Dim sSQL As String = "SELECT * FROM Table1" Dim oDataAdapter As OdbcDataAdapter = New OdbcDataAdapter(MySQL, MyConn)Dim oDataSet As DataSet = New DataSet() oDataAdapter.Fill(oDataSet) GridView1.DataSource = ds.Tables("test").DefaultView GridView1.DataBind() End Sub End Class iam getting an error as "ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified" plz correct this and also tell me the code for same program using oledb
upload a MS Word file to mysql database   (293 Views)
I am new to asp.net and I am having a problem when I try to upload a word document from asp.net to Mysql database. I have a field of type mediumblob in mysql table. I looked for some example online but found a few that use Access database or SQL databse. but they didnot help me in solving the problem. I need to be able to upload the file and save it to the mysql database and then I should also be able to view the file that was stored in the database.