0

hey, i have a problem regarding the format of the date format. in the form i have the date format in dd/mm/yyyy and when i try to save the date in that format in sql database, it's not accepting in that format. but i need to save the date in the above format in sql database.

any one can tell me how can i change the date format in sqldatabase. i need it very urgently

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by sknake
0

Seperate date string variable into year month date format and send it database. while retrieving use covnert keyword and retrieve it in 103 format

0

You should use parameterized SQL so you don't have to worry about formatting:

private void button2_Click(object sender, EventArgs e)
    {
      const string connStr = "Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;";
      const string query = "Select * From Invoice Where (InHomeDate BETWEEN @Date1 and @Date2)";
      using (SqlConnection conn = new SqlConnection(connStr))
      {
        conn.Open();
        using (SqlCommand cmd = new SqlCommand(query, conn))
        {
          cmd.Parameters.Add(new SqlParameter("@Date1", SqlDbType.DateTime)).Value = DateTime.Today.AddDays(-180);
          cmd.Parameters.Add(new SqlParameter("@Date2", SqlDbType.DateTime)).Value = DateTime.Today;
          using (SqlDataReader dr = cmd.ExecuteReader())
          {
            DataTable dt = new DataTable();
            dt.Load(dr);
            dataGridView1.DataSource = dt;
          }
        }
      }
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.