Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to update a MySQL table using C#?

Posted on 2009-07-15
4
Medium Priority
?
433 Views
Last Modified: 2013-12-17

Hello group,

How can I update a record in MySQL table?
I can select and get the resuls but I cannot update any record.

Thanks.

strSQLStmt1 = "";
 strSQLStmt1 = "UPDATE table set  fld= '" + t.score.Trim().ToString() + "' WHERE Id = '" + t.applicant_id.Trim() + "' ";
                        Reader1 = command.ExecuteReader();
                        Reader1.Close();

Open in new window

0
Comment
Question by:akohan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 24865730
Use

   int rowsUpdated;
   rowsUpdated = command.ExecuteNonQuery();

instead of ExecuteReader(). rowsUpdated is just to show what is returned.
0
 

Author Comment

by:akohan
ID: 24865866


Thanks I'm sure that is the answer but I'm getting

Cannot implicitly convert type 'int' to 'MySql.Data.MySqlClient.MySqlDataReader'
0
 

Author Comment

by:akohan
ID: 24865879

OK I fixed that but my return value is -1 !

What could cause that? in msdn page says a rollback might cause it. Is this something I should take care of in db?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24868884
I don't see where in code you assigned the sql query to the command object. See notation below. Also, you can set a breakpoint at line 6 below, mouse over the strSQLStmtml variable and see the actual SQL statement that will be executed against the DB. You can try manually running that query against the DB to see if it generates any errors.
strSQLStmt1 = "";
strSQLStmt1 = "UPDATE table set  fld= '" + t.score.Trim().ToString() + "' WHERE Id = '" + t.applicant_id.Trim() + "' ";
 
command.CommandText = strSQLStmtl;
 
Reader1 = command.ExecuteReader();
Reader1.Close();

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question