INSERT DATA IN DATABASE USING WINDOWS APPLICATION C#

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C#
 638  View(s)
Ratings:
Rate this:
I want to Insert data in Database using windows Application c# .please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: Insert data in Database using windows Application c#

     

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!