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
323 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
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with error in Query 2 31
How to seperate number and letters from a string 3 22
Easy filter aspnet 2 24
Adding items to a C# list incrementally 5 28
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

789 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