0
我只需要一點關於下面的代碼的幫助。我得到的字符串沒有作爲一個有效的日期時間這條線recgonized。我嘗試使用DateTime.TryParse,但它只是給了我錯誤和Convert.ToDateTime給我同樣的錯誤。TextBox字符串未被識別爲有效的DateTime
if(DateTime.Parse(TextBox3.Text)>=d1 && DateTime.Parse(TextBox4.Text)<=d2) {
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source = KEVS; Initial Catalog = booking; Integrated Security = True; ");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
SqlDataReader dr;
con.Open();
cmd = new SqlCommand("select * from booking1 where busno='" + DropDownList1.SelectedItem.Text + "'", con);
// cmd.CommandText = "Select * from booking1 where date='" + TextBox3.Text + "' and busno='" + DropDownList1.Text + "'";
dr = cmd.ExecuteReader();
if (dr.Read())
{
d1 = dr.GetDateTime(2);
d2 = dr.GetDateTime(3);
}
if(DateTime.Parse(TextBox3.Text)>=d1 && DateTime.Parse(TextBox4.Text)<=d2)
{
Label14.Text = "bus is already booked by someone";
}
「TextBox3.Text」和「TextBox4.Text」中的日期格式是什麼? – Tim
「TextBox3.Text」和「TextBox4.Text」的值是什麼?您也可能會收到很多關於SQL注入的評論。 –
@MetroSmurf ..並釋放一次性資源,並'選擇*'.. – stuartd