How To Save Record In MySQL With ASP.NET in Two Minutes

How To Save Record In MySQL With ASP.NET in Two Minutes

How to save record in asp.net with mysql using the vs2010 software on the open it and create a web site the add two text box on the page and on button add on it .
out put on the ruining web pages image
s like this  then open the mysql in your local host setting and create a table of add attendance

--
-- Table structure for table `addattendance`
--

CREATE TABLE IF NOT EXISTS `addattendance` (
  `id` mediumint(9) NOT NULL AUTO_INCREMENT,
  `EmpFullName` varchar(130) NOT NULL,
  `Empid` varchar(130) NOT NULL,
  `TimeIn` varchar(130) CHARACTER SET utf8 NOT NULL,
  `Note` varchar(130) NOT NULL,
  `Status` varchar(130) NOT NULL,
  `UserName` varchar(130) NOT NULL,
  `UserId` varchar(130) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

----------------------------------------------------------------------------------------------------------------
CS Code- Events on Click button code and using namespace 
using MySql.Data.MySqlClient; 
its very urgent 



protected void Button1submit_Click(object sender, EventArgs e)
    {  
        string Status = "Present";

        string TimeI = TxtTimeIn.Text;
        string Note = TxtNote.Text;

        string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        using (MySqlConnection con = new MySqlConnection(constr))
        {
            using (MySqlCommand cmd = new MySqlCommand("INSERT INTO addattendance (EmpFullName,Empid,TimeIn, Note,Status,UserName,UserId) VALUES (@EmpFullName,@Empid,@TimeIn, @Note,@Status,@UserName,@UserId)"))
            {
                using (MySqlDataAdapter sda = new MySqlDataAdapter())
                {

                    cmd.Parameters.AddWithValue("@EmpFullName", Label2username.Text );
                    cmd.Parameters.AddWithValue("@Empid", Session["empid"]);
                    cmd.Parameters.AddWithValue("@TimeIn", TimeI);
                    cmd.Parameters.AddWithValue("@Note", Note);
                    cmd.Parameters.AddWithValue("@Status", Status);
                    cmd.Parameters.AddWithValue("@UserName", Label2username.Text);
                    cmd.Parameters.AddWithValue("@UserId", "UserID");
                    cmd.Connection = con;
                    con.Open();
                    cmd.ExecuteNonQuery();
                    lblMsgSend.Text = "Your Attendance is Add Sucessfully .";

                    con.Close();
                }
            }
        }
       ------------------------------------end of code ---------------------------------------------------
Web configuration code-


<connectionStrings>
 
     <add name="ConnectionString" connectionString="Data Source=localhost;port=3306;Initial Catalog=ems;User Id=root;password="/>-->
      </connectionStrings>


after this setting then run the web pages and save record on it your mysql data save on successfully.
if any problem generate for save the data on mysql so please ask the query on me.

thanks   

Post a Comment

Previous Post Next Post

Design a beautiful Login/Signup (with google map) in Flutter | Flutter UI | VS Code | iOS Android