参数化查询需要参数'@units',这是未提供的

时间:2018-03-10 20:47:17

标签: c# sql-server

我遇到了这个例外:

  

System.Data.SqlClient.SqlException:'参数化查询'(@ Date datetime,@ Type nvarchar(11),@ Registration nvarchar(6),@ De'需要参数'@SyntDate',这是未提供的。“

我的插入代码是:

private void simpleButton1_Click(object sender, EventArgs e)
{
    if (baglanti.State == ConnectionState.Closed)
    {
        baglanti.Open();

        SqlCommand cmd = new SqlCommand(@"INSERT INTO LogBook 
                        (Date, Type, Registration, DepPlace, DepTime, 
                        ArrPlace, ArrTime, Se, Me, MultiPilot, 
                        TotalTime, NamePic, Day, Night, NghtCon, 
                        IfrCon, Pic, CoPilot, Dual, Instructor, 
                        SyntDate, ACType, TimeOfSession, Remarks) " +
                        @"VALUES(@Date, @Type, @Registration, 
                        @DepPlace, @DepTime, @ArrPlace, @ArrTime, @Se, 
                        @Me, @MultiPilot, @TotalTime, @NamePic, @Day, 
                        @Night, @NghtCon, @IfrCon, @Pic, @CoPilot, 
                        @Dual, @Instructor, @SyntDate, @ACType, 
                        @TimeOfSession, @Remarks)", baglanti);

        cmd.Parameters.AddWithValue("@Date", dateEdit1.EditValue);
        cmd.Parameters.AddWithValue("@Type", comboBoxEdit1.Text);
        cmd.Parameters.AddWithValue("@Registration", textEdit1.Text);
        cmd.Parameters.AddWithValue("@DepPlace", comboBoxEdit3.Text);
        cmd.Parameters.AddWithValue("@DepTime", Convert.ToDateTime(string.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, textEdit4.Text)));   
        cmd.Parameters.AddWithValue("@ArrPlace", comboBoxEdit4.Text);
        cmd.Parameters.AddWithValue("@ArrTime", Convert.ToDateTime(string.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, textEdit6.Text)));    
        cmd.Parameters.AddWithValue("@Se", Convert.ToDateTime(string.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, textEdit7.Text)));      
        cmd.Parameters.AddWithValue("@Me", Convert.ToDateTime(string.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, textEdit8.Text)));         
        cmd.Parameters.AddWithValue("@MultiPilot", Convert.ToDateTime(string.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, textEdit9.Text))); 
        cmd.Parameters.AddWithValue("@TotalTime", Convert.ToDateTime(string.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, textEdit10.Text))); 
        cmd.Parameters.AddWithValue("@NamePic", textEdit11.Text);
        cmd.Parameters.AddWithValue("@Day", Convert.ToInt32(textEdit12.Text));
        cmd.Parameters.AddWithValue("@Night", Convert.ToInt32(textEdit13.Text));
        cmd.Parameters.AddWithValue("@NghtCon", Convert.ToDateTime(string.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, textEdit14.Text))); 
        cmd.Parameters.AddWithValue("@IfrCon", Convert.ToDateTime(string.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, textEdit15.Text)));  
        cmd.Parameters.AddWithValue("@Pic", Convert.ToDateTime(string.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, textEdit16.Text)));    
        cmd.Parameters.AddWithValue("@CoPilot", Convert.ToDateTime(string.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, textEdit17.Text))); 
        cmd.Parameters.AddWithValue("@Dual", Convert.ToDateTime(string.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, textEdit18.Text)));     
        cmd.Parameters.AddWithValue("@Instructor", Convert.ToDateTime(string.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, textEdit19.Text))); 
        cmd.Parameters.AddWithValue("@SyntDate", dateEdit2.EditValue);
        cmd.Parameters.AddWithValue("@ACType", comboBoxEdit2.Text);
        cmd.Parameters.AddWithValue("@TimeOfSession", Convert.ToDateTime(string.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, textEdit21.Text))); 
        cmd.Parameters.AddWithValue("@Remarks", textEdit22.Text);

        cmd.ExecuteNonQuery();
        cmd.Dispose();

        baglanti.Close();
        MessageBox.Show("New record has completed");

        listeleme();
    }
}

0 个答案:

没有答案