Member 13317783 Ответов: 1

Почему я не могу его запустить ?


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; }
    }
}


Что я уже пробовал:

вставка данных
неправильный код в этой строке

УМК . CommandType = CommandType.Хранимая процедура;

Kornfeld Eliyahu Peter

Из образца, который вы сюда вставили, он даже не компилируется...

1 Ответов

Рейтинг:
1

F-ES Sitecore

SqlCommand cmd = new SqlCommand();


Возьмите книгу по c# и получите лучшее понимание основ, вы будете бороться за то, чтобы сделать что-то более продвинутое без хорошего понимания основ, таких как создание объекта.


BillWoodruff

Хороший совет, но это комментарий, а не решение.

F-ES Sitecore

Посмотрите на его код, посмотрите на мой код. Это решение.