Solved

How to use a asp.net button, on click to insert the values of text boxes into a MySql Database?

Posted on 2009-05-14
7
324 Views
Last Modified: 2012-05-07
I am designing a web page in visual studio.net 2005 using C#, ajax, asp.net 2.0 and has a MySql database tied in that displays the information from the database in a gridview.

My question is how do i make a button that will allow me to take values entered into a series of text boxes and insert the values into the MySql database table employeestatus on button click. Thanks for ya time!
0
Comment
Question by:Figle
[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
7 Comments
 
LVL 39

Assisted Solution

by:abel
abel earned 150 total points
ID: 24388542
Instead of showing it to you line by line, please take a look at this project, it contains all what you want and possibly a bit more. There's not a lot of explanation going on, but I think most is quite self-explanatory. If you have follow-up questions, I'll be happy to help. http://www.codeproject.com/KB/database/mysqlinaspnet.aspx
0
 
LVL 27

Expert Comment

by:nmarun
ID: 24388543
0
 
LVL 5

Assisted Solution

by:satheeshm
satheeshm earned 50 total points
ID: 24388596
private const string ConnStr =
   "Driver={MySQL ODBC 3.51 Driver};Server=localhost;" +
   "Database=test;uid=root;pwd=;option=3";


public sub button_click()
{
      using(OdbcConnection con = new OdbcConnection(ConnStr))
        using(OdbcCommand cmd = new OdbcCommand("INSERT INTO sample" +
                                "(name, address) VALUES (?,?)", con))
        {
            cmd.Parameters.Add("@name", OdbcType.VarChar,
                               255).Value = txtName.Text.Trim();
            cmd. Parameters.Add("@address", OdbcType.VarChar,
                                255).Value = txtAddress.Text.Trim();
       
            con.Open();
            cmd.ExecuteNonQuery();
            BindDataGrid();
        }
}
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

Author Comment

by:Figle
ID: 24399227
Thanks im trying out these solutions now, but im not using a datagrid thou im using a gridview, does it matter?
0
 
LVL 27

Expert Comment

by:nmarun
ID: 24399251
Most of the idea is the same, but there are a few subtle changes though. Nothing that will hold you back.
0
 

Author Comment

by:Figle
ID: 24404104
I decited to use interface of the gridview instead of creating new buttons, and i got the update working but, im not sure how to have the WHERE target individual records instead of the whole column. Here is my working update code.

UpdateCommand="UPDATE employeestatus SET `First Name` = ? WHERE (`Badge` = Badge)

It updates the whole First Name column because my WHERE is not correct, the badge field is the primary key field. How can i get it to target only the record that i edit?

0
 
LVL 27

Accepted Solution

by:
nmarun earned 300 total points
ID: 24404764
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Amazon S3 Images with .Net 3 29
Need to sort columns in DataGridView 4 36
C# XML Get Values 4 33
Why can I INSERT a DATETIME record into mysql but I can't UPDATE it? 15 32
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 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