插入查询没有给出任何错误,但数据没有插入到数据库中。当我在sql server中检查数据库时,似乎没有数据插入。我不确定代码的哪一部分有错误。
以下代码:
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace PayrollSystem05
{
public partial class employee : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAdd_Click1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-M0G68DT\\SQLEXPRESS;Initial Catalog=PRS;Integrated Security=True");
SqlCommand cmd = new SqlCommand(@"INSERT INTO [payslip].[employee]
([emp_id]
,[emp_name]
,[emp_ic]
,[emp_address]
,[emp_mobile]
,[emp_email]
,[emp_startdate])
VALUES
('"+ txtID.Text +"', '"+ txtName.Text +"', '"+ txtIC.Text +"', '"+ txtAdd.Text + "', '"+ txtMob.Text +"', '"+ txtEmail.Text +"', '" + txtStart.Text + "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('Employee added successfully.')</script>");
}
}
}```