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
320 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now