我尝试使用visual studio在数据库中插入数据但我有一些错误

时间:2016-11-08 19:08:59

标签: c# asp.net

值不会进入数据库我添加信息但不更新数据库服务器。

namespace InsertDatabase00
{
    public partial class Form1 : Form
    {
        SqlCommand cmd = new SqlCommand();
        SqlConnection con;
        SqlDataAdapter da;

        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            con = new SqlConnection(@"Data Source=PHOENIX\SQLEXPRESS1;Initial Catalog=Itzoz;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=True");
            con.Open();
            cmd = new SqlCommand("Insert Into EmpData(Name,Email,Gender) values (@Name,@Email,@Gender)", con);
            cmd.Parameters.Add("@Name", textBox1.Text);
            cmd.Parameters.Add("@Email", textBox2.Text);
            cmd.Parameters.Add("@Gender", comboBox1.SelectedItem.ToString());
            cmd.ExecuteNonQuery();
        }
    }
}

0 个答案:

没有答案