不保存新记录到SQL Server数据库

Ame*_*awi -1 c# sql sql-server asp.net

问题是我的代码没有使用asp.net c#将新记录插入/保存到我的SQL Server数据库中,并且没有给我任何错误.

这是我的代码:

 public partial class AddNews_AddNews : System.Web.UI.Page
 {
        protected SqlConnection _connection;
        protected SqlCommand _command;
        protected SqlDataAdapter _adp;
        protected System.Data.DataTable _tbl;

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            prepareConnection();
            _command.CommandText = "INSERT INTO" + drbdlSection.SelectedItem + "(Title,Contect) VALUES (" + titleTextBox.Text + "," + CKEditor1.Text + ");";
        }

        protected void prepareConnection()
        {
            _connection = new SqlConnection(@"Data Source=localhost;Initial Catalog=BrainStorms;User ID=sa;Password=xxx");
            _connection.Open();
            _command = new SqlCommand();
            _command.Connection = _connection;
        }
    }
Run Code Online (Sandbox Code Playgroud)

dpw*_*dpw 5

您需要添加_command.ExecuteNonQuery();到Button1_Click1()方法的末尾.您已设置要运行的查询,但实际上从未实际运行它.