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
326 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

630 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