0

以下のコードを取得して、SQL Server CE データベースに何ヶ月も書き込もうとしましたが、成功しませんでした。私の試行キャッチはスローされたエラーをキャッチしませんが、データは書き込まれません。私がこれを行っている方法に誰かが何か問題があると思いますか?

conn = new SqlCeConnection("Data Source = LaZSolutions.sdf");
conn.Open();

var id = Guid.NewGuid();

SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "INSERT INTO Customers (FirstName, LastName, Address, City, State, Zip, Phone, Mobile, Email, CustomerNum) VALUES(@FirstName, @LastName, @Address, @City, @State, @Zip, @HomePhone, @MobilePhone, @Email, @CustomerNum)";

cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@FirstName", txtFName.Text);
cmd.Parameters.AddWithValue("@LastName", txtLName.Text);
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@HomePhone", txtHPhone.Text);
cmd.Parameters.AddWithValue("@MobilePhone", txtMPhone.Text);
cmd.Parameters.AddWithValue("@City", txtCity.Text);
cmd.Parameters.AddWithValue("@State", txtState.Text);
cmd.Parameters.AddWithValue("@Zip", txtZip.Text);
cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
cmd.Parameters.AddWithValue("@CustomerNum", id);

cmd.ExecuteNonQuery();

conn1 = new SqlCeConnection("Data Source = LaZSolutions.sdf");
conn1.Open();

SqlCeCommand cmd1 = conn1.CreateCommand();
cmd1.CommandText = "INSERT INTO Orders (OrderNum, OrderDate, Cost, [Open], Comments) VALUES(@OrderNum, @OrderDate, @Cost, @Open, @Comments)";

cmd1.CommandType = CommandType.Text;
cmd1.Connection = conn1;
cmd1.Parameters.AddWithValue("@OrderNum", txtOrderNum.Text);
cmd1.Parameters.AddWithValue("@OrderDate", txtOrderdate.Text);
cmd1.Parameters.AddWithValue("@Cost", lblPrice.Text);
cmd1.Parameters.AddWithValue("@Open", open);
cmd1.Parameters.AddWithValue("@CustomerNum", id);
cmd1.Parameters.AddWithValue("@Comments", txtComments.Text);

cmd1.ExecuteNonQuery();
conn1.Close();
conn.Close();
4

1 に答える 1