Server Error in '/' Application.
Conversion failed when converting date and/or time from character string.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting date and/or time from character string.
Source Error:
Line 28: SqlDataAdapter da = new SqlDataAdapter(cmd);
Line 29: DataSet ds = new DataSet();
Line 30: da.Fill(ds);
Line 31: //DataList2.DataSource = ds;
Line 32: //DataList2.DataBind();
protected void Page_Load(object sender, EventArgs e)
{
//LoadChatbox();
get_User();
Load_Frends();
}
public void LoadChatbox()
{
DateTime date = DateTime.Now;
string date3 = date.ToString("dd-MM-yyyy");
//string agent = Session["Admin"].ToString();
conn.Open();
string str = "select * from Chatbox where Sender='"+Label1.Text+ "' and Reciever='" + Label2.Text + "' or Sender='" + Label2.Text + "' and Reciever='" + Label1.Text + "' and Date='"+date3+"' ORDER BY ID";
SqlCommand cmd = new SqlCommand(str, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
//DataList2.DataSource = ds;
//DataList2.DataBind();
DataList3.DataSource = ds;
DataList3.DataBind();
conn.Close();
//ScriptManager.RegisterStartupScript(this.Page, typeof(Panel), "PanelChatContent", ";ScrollToBottom();", true);
}