How to Insert/save data in database c# window form

How to Insert/save data in database c# visual studio 

Database window form

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.Data.SqlClient;  
namespace Insert_data_into_table  
    public partial class Form1 : Form  
        public Form1()  
        private void button1_Click(object sender, EventArgs e)  
            //SqlConnection con = new SqlConnection("Data Source=NiluNilesh;Integrated Security=True");  
            SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");  
            SqlCommand cmd = new SqlCommand("sp_insert", con);  
            cmd.CommandType = CommandType.StoredProcedure;  
            cmd.Parameters.AddWithValue("@name", textBox1.Text);  
            cmd.Parameters.AddWithValue("@email", textBox2.Text);  
            cmd.Parameters.AddWithValue("@phone", textBox3.Text);  
            cmd.Parameters.AddWithValue("@address", textBox4.Text);  
            int i = cmd.ExecuteNonQuery();  
            if (i!=0)  
                MessageBox.Show(i + "Data Saved");   
        public static void main(string[] args)  
            Application.Run(new Form1());  


Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *


%d bloggers like this: