Home > DeveloperSection > Forums > Insert data in Database using windows Application c#
Ankit Singh

Total Post:341

Points:2389
Posted on    December-13-2015 10:15 PM

 C# C#  Database  Windows Controls 
Ratings:


 1 Reply(s)
 248  View(s)
Rate this:
I want to Insert data in Database using windows Application c# .please help me.


aditya kumar Patel

Total Post:244

Points:1736
Posted on    December-13-2015 10:29 PM

 

using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
using System.Data.SqlClient;
using System.Data;
namespace WindowsForums
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }      
        private void save()
        {
            SqlConnection cn = new SqlConnection("Data Source=MSCLIENT-006;Initial Catalog=forum;Persist Security Info=True;User ID=sa;Password=mindstick");
            SqlCommand cmd = new SqlCommand();
            string sqlrt = "insert into [Employee] ([Emp_Name],[Emp_Sal],[Location]) values('" + txtempName.Text + "','" + txtempSal.Text + "','" + txtempAddress.Text + "')";
            cn.Open();
            cmd.Connection = cn;
            cmd.CommandText = sqlrt;
            cmd.ExecuteNonQuery();
            cn.Close();
        }
        private void clear()
        {
            txtempName.Text = "";
            txtempSal.Text = "";
            txtempAddress.Text = "";
        }

        private void btnSave_Click(object sender, System.EventArgs e)
        {
            save();
            clear();
        }

        private void btncleare_Click(object sender, System.EventArgs e)
        {
            clear();
        }

        private void btnclose_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }
    }


}

 


Modified On Dec-13-2015 10:36:51 PM

Don't want to miss updates? Please click the below button!

Follow MindStick