开发者

How to Convert using of SQLite to Simple SQL command in C#

开发者 https://www.devze.com 2022-12-25 08:26 出处:网络
I want to get start with DayPilot control I do not use SQLite and this control documented based on SQLite.

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.ht开发者_运维知识库ml

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();
    }
  }


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消