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

x
?
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
Medium Priority
?
328 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 600 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 200 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

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 1200 total points
ID: 24404764
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

730 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