views:

75

answers:

2

I want to get start with DayPilot control I do not use SQLite and this control documented based on SQLite.

I want to use SQL instead of SQLite so if you can, please do this for me.

main site with samples http://www.daypilot.org/calendar-tutorial.html

The database contains a single table with the following structure

CREATE TABLE event (  id VARCHAR(50),  name VARCHAR(50),  eventstart DATETIME,  eventend DATETIME);

Loading Events

  private DataTable dbGetEvents(DateTime start, int days)    {
     SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT [id], [name], [eventstart], [eventend] FROM [event] WHERE NOT (([eventend] <= @start) OR ([eventstart] >= @end))", ConfigurationManager.ConnectionStrings["db"].ConnectionString);
    da.SelectCommand.Parameters.AddWithValue("start", start);
    da.SelectCommand.Parameters.AddWithValue("end", start.AddDays(days));
    DataTable dt = new DataTable();
    da.Fill(dt);
    return dt;
  }

Update

  private void dbUpdateEvent(string id, DateTime start, DateTime end)    {
    using (SQLiteConnection con = new SQLiteConnection(ConfigurationManager.ConnectionStrings["db"].ConnectionString))
    {
        con.Open();
        SQLiteCommand cmd = new SQLiteCommand("UPDATE [event] SET [eventstart] = @start, [eventend] = @end WHERE [id] = @id", con);
        cmd.Parameters.AddWithValue("id", id);
        cmd.Parameters.AddWithValue("start", start);
        cmd.Parameters.AddWithValue("end", end);
        cmd.ExecuteNonQuery();
    }
  }
+1  A: 

you can create your db in sql server, after that you only need to change SQLiteCommand to SQLCommand. you don't need to change anything except connection string info.

masoud ramezani
I'd change connction string to my new SQL server database ( and this is not the answer ) I want to convert this part of sql lite code into t-sql
Nasser Hadjloo
you only need to change SQLiteCommand to SQLCommand.
masoud ramezani
+1  A: 

Instead of

private void dbUpdateEvent(string id, DateTime start, DateTime end)    {
using (SQLiteConnection con = new SQLiteConnection(ConfigurationManager.ConnectionStrings["db"].ConnectionString))
   {
    con.Open();
    SQLiteCommand cmd = new SQLiteCommand("UPDATE [event] SET [eventstart] = @start, [eventend] = @end WHERE [id] = @id", con);
    cmd.Parameters.AddWithValue("id", id);
    cmd.Parameters.AddWithValue("start", start);
    cmd.Parameters.AddWithValue("end", end);
    cmd.ExecuteNonQuery();
    }
}

You should be able to use

private void dbUpdateEvent(string id, DateTime start, DateTime end)    {
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["db"].ConnectionString))
   {
    con.Open();
    SqlCommand cmd = new SqlCommand("UPDATE [event] SET [eventstart] = @start, [eventend] = @end WHERE [id] = @id", con);
    cmd.Parameters.AddWithValue("id", id);
    cmd.Parameters.AddWithValue("start", start);
    cmd.Parameters.AddWithValue("end", end);
    cmd.ExecuteNonQuery();
    }
}

You also need to add; a project reference to System.Data and using System.Data.SqlClient at the top of the class.

Keith Bloom