Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Sql;
namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=""C:\Users\pc\Documents\Visual Studio 2012\Projects\WindowsFormsApplication3\WindowsFormsApplication3\testing.mdf"";Integrated Security=True;Connect Timeout=30");
        public Form1()
        {
            InitializeComponent();

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //SqlConnection con = new SqlConnection("Data Source=NiluNilesh;Integrated Security=True");  
            SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=""C:\Users\pc\Documents\Visual Studio 2012\Projects\WindowsFormsApplication3\WindowsFormsApplication3\testing.mdf"";Integrated Security=True;Connect Timeout=30");
            SqlCommand cmd = new SqlCommand 
            cmd . CommandType  = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@ID", textBox1.Text);
            cmd.Parameters.AddWithValue("@Domain", textBox2.Text);
            cmd.Parameters.AddWithValue("@Registar", textBox3.Text);
            cmd.Parameters.AddWithValue("@Registration_Date", textBox4.Text);
            cmd.Parameters.AddWithValue("@Expiration_Date", textBox5.Text);
            cmd.Parameters.AddWithValue("@Update_Date", textBox6.Text);
            cmd.Parameters.AddWithValue("@Name_Servers", textBox7.Text);
            con.Open();
            int i = cmd.ExecuteNonQuery();

            con.Close();

            if (i != 0)
            {
                MessageBox.Show(i + "Data Saved");
            }  
        }

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

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.ShowDialog(); // Shows Form2
        }

        public object StoredProcedure { get; set; }
    }
}


What I have tried:

insert Data
the incorrect code in this line

cmd . CommandType = CommandType.StoredProcedure;
Posted
Updated 19-Jul-17 4:03am
Comments
Kornfeld Eliyahu Peter 19-Jul-17 9:21am    
From the sample you pasted here it not even compile...

1 solution

SqlCommand cmd = new SqlCommand();


Get a book on c# and get a better understanding of the basics, you will struggle to do anything more advance without a good understanding of the basics such as how to create an object.
 
Share this answer
 
v3
Comments
BillWoodruff 19-Jul-17 15:03pm    
Good advice, but, this is a commentm, not a solution.
F-ES Sitecore 19-Jul-17 15:15pm    
Look at his code, look at my code. It is a solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900