private void AddMenuButton_Click(object sender, EventArgs e)
{
if (IsValidated())
{
String query = "INSERT INTO Empoyee_GI (Name,[Father Name], Birthdate, Address, City, Zone, Province, [Cell Number], Email, [Employement Status], [Hire Date], [Renewal Date], Location, Position, BPS, Department, Gender, [Maritial Status], CNIC, [Employement Number]) VALUES (@Name,@[Father Name], @Birthdate, @Address, @City, @Zone, @Province, @[Cell Number], @Email, @[Employement Status], @[Hire Date], @[Renewal Date], @Location, @Position, @BPS, @Department, @Gender, @[Maritial Status], @CNIC, @[Employement Number])";
using (SqlCeConnection connection = new SqlCeConnection(@"Data Source=c:\users\the doom's day\documents\visual studio 2012\Projects\StaffFiles1.0\StaffFiles1.0\Employee_DB.sdf"))
using (SqlCeCommand command = new SqlCeCommand(query, connection))
{
// a shorter syntax to adding parameters
command.Parameters.Add("@Name", SqlDbType.NChar).Value = name_TextBox.Text;
command.Parameters.Add("@[Father Name]", SqlDbType.NChar).Value = father_Name_TextBox.Text;
// a longer syntax for adding parameters
command.Parameters.Add("@Birthdate", SqlDbType.NChar).Value = birthdate_DateTimePicker.Text;
command.Parameters.Add("@Address", SqlDbType.NChar).Value = address_TextBox.Text;
command.Parameters.Add("@City", SqlDbType.NChar).Value = city_ComboBox.Text;
command.Parameters.Add("@Zone", SqlDbType.NChar).Value = zone_ComboBox.Text;
command.Parameters.Add("@Province", SqlDbType.NChar).Value = province_ComboBox.Text;
command.Parameters.Add("@[Cell Number]", SqlDbType.NChar).Value = cell_Number_TextBox.Text;
command.Parameters.Add("@[Employement Status]", SqlDbType.NChar).Value = employement_Status_ComboBox.Text;
command.Parameters.Add("@[Hire Date]", SqlDbType.NChar).Value = hire_Date_DateTimePicker.Text;
command.Parameters.Add("@[Renewal Date]", SqlDbType.NChar).Value =renewal_Date_DateTimePicker.Text;
command.Parameters.Add("@[Location]", SqlDbType.NChar).Value = location_ComboBox.Text;
command.Parameters.Add("@[Position]", SqlDbType.NChar).Value = position_ComboBox.Text;
command.Parameters.Add("@BPS", SqlDbType.NChar).Value = bPS_ComboBox.Text;
command.Parameters.Add("@Department", SqlDbType.NChar).Value = department_ComboBox.Text;
command.Parameters.Add("@Gender", SqlDbType.NChar).Value = gender_ComboBox.Text;
command.Parameters.Add("@[Maritial Status]", SqlDbType.NChar).Value = maritial_Status_ComboBox.Text;
command.Parameters.Add("@CNIC", SqlDbType.NChar).Value = cNICTextBox.Text;
command.Parameters.Add("@[Employement Number]", SqlDbType.NChar).Value = employement_Number_TextBox.Text;
// make sure you open and close(after executing) the connection
connection.Open();
command.ExecuteNonQuery(); // I get the error here this line doenot execute. I am really worried about this.
connection.Close();
}
}
我想我的權利根據上面的代碼,但它拋出一個異常:的SQL Server CE插入查詢工作不細
類型的未處理的異常「System.Data.SqlServerCe.SqlCeException 「發生在System.Data.SqlServerCe.dll
什麼是異常的_message_? – gunr2171
請勿在參數名稱中使用空格。 –
在System.Data.SqlServerCe.dll中發生類型爲「System.Data.SqlServerCe.SqlCeException」的未處理異常。 – Paramour