0
我正在使用sql server 2012和我有一個DOB列在我的表和類型是nvarchar(50),我使用日期數據類型之前,我改變爲nvarchar。我通過使用三個組合框(月份,日期,年份)接受了出生日期,我附上了代碼。請仔細觀察並幫助我。謝謝轉換日期和時間從字符串轉換失敗
string dob = cmbDate.Text + "/" +cmbMonth.Text + "/"+cmbYear.Text;
query= "Insert into Admissions(
Admission_date,
Student_name,
Father_name,
Mother_name,
DOB,
Gender,
Address,
State,
City,
Pincode,
Admission_for,
Previous_school,Fees
)
values
('"+txtAdmDate.Text+"','"+
txtStudentName.Text +"','"+
txtFatherName.Text +"','"+
txtMotherName.Text +"','"+
dob+"','"+
gender+"','"+
txtAddress.Text +"','"+
txtState.Text +"','"+
txtCity+"','"+
txtPincode.Text +"','"+
cmbClass.Text+"','"+
txtPreviousSchool.Text +"','"+
txtFees.Text +"')";
cmd = new SqlCommand(query,con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
瞭解如何使用參數化查詢,提供參數用正確的類型。瞧!問題已經解決了。 –
在query = ...之前加上這個... >>'dob ='''+ dob +'''' –
我想用ad hoc查詢。請告訴我爲什麼我得到這個錯誤。 – SATYA