类型' System.Data.SqlClient.SqlException'的例外情况System.Data.dll中发生错误

时间:2015-12-23 10:12:27

标签: c# sql-server visual-studio visual-studio-2015 sql-server-2014-express

我正在制作电话乳制品,一个错误即将来临

  

类型' System.Data.SqlClient.SqlException'的异常发生在System.Data.dll

请告诉我我在哪里做错了这是我的代码错误来自con.Open();

using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Telephone
{
    public partial class Phone : Form
    {
        SqlConnection con = new SqlConnection("Data Source =ZOHAB/SQLEXPRESS;
     Initial Catalog = bscs; Integrated Security = True");

        public Phone()
        {
            InitializeComponent();
        }

        private void Phone_Load(object sender, EventArgs e)
        {

        }
        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Clear();
            textBox3.Text = "";
            textBox4.Clear();
            comboBox1.SelectedIndex = -1;
            textBox1.Focus();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            con.Open();

            SqlCommand cmd = new SqlCommand (@"INSERT INTO 5th

                (First Name,Last Name,Mobile,Email,Catagory)

                VALUES ('"+ textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + comboBox1.Text + "')",con);
            cmd.ExecuteNonQuery();
            con.Close();
        }
    }
}

0 个答案:

没有答案