插入值,我有這個語法對我的程序:從字符串轉換日期和/或時間時轉換失敗。從的DateTimePicker
con.Open();
SqlCommand cmdInsert = new SqlCommand();
cmdInsert.Connection = con;
cmdInsert.CommandText =
"INSERT INTO Customers VALUES (@Firstname, @LastName, @Birthdate)";
cmdInsert.Parameters.Add("@Firstname", SqlDbType.VarChar).Value = txtFirstname.Text;
cmdInsert.Parameters.Add("@LastName", SqlDbType.VarChar).Value = txtLastName.Text;
cmdInsert.Parameters.Add("@BIrthdate", SqlDbType.DateTime).Value = dtpBirthdate.Value;
每當執行這段代碼,我得到的錯誤
「轉換,從性格 轉換日期和/或時間時失敗字符串「
我猜測問題根源於」dtpBirthdate.Value「語法。我試圖尋找這部分語法的正確格式,但我從來沒有幸運。
附加信息:
我也改變dtpBirthdate.Value
到DBNull.Value
和它產生同樣的錯誤。
請添加一些關於您的代碼的具體描述。它有助於人們更好地理解您的解決方案。 – Rachcha
我的意思是請編輯你的答案並添加你的描述。此外,添加說明和更多混淆的代碼。 – Rachcha