簡體   English   中英

如何在沒有SqlDataSource的情況下將mysql連接到DevExpress ASPxScheduler

[英]How to connect mysql to DevExpress ASPxScheduler without SqlDataSource

我有一個ASP.net項目,我正在尋找他們想要使用MySQL。 我已經習慣了SQL服務器,但使用mySQL應該不是問題。

通常情況下,控件希望綁定一個SqlDataSource,但MySQL不能使用它(來自此站點上的其他帖子)。

連接MySQL和DevExpress ASPxScheduler的最佳方法是什么,以便您可以創建約會?

為什么不是ObjectDataSource並寫入數據層? 或者使用LLBLGen,我認為它適用於MySQL。 我見過的一個警告是MySQL ODBC和ADO驅動程序存在元數據問題。

我最終使用了objectdatasource和ObjectCreated方法並編寫了datalayer以將記錄插入到mysql數據庫中。 我已經包含了我的代碼,只是因為有些人需要一些邏輯幫助。

protected void appointmentsDataSource_ObjectCreated(object sender, ObjectDataSourceEventArgs e)
    {
        e.ObjectInstance = new CustomEventDataSource(GetCustomEvents());
    }

  public void InsertAppointment()
    {

        //need to reformat the dates
        string tempStartDate;
        string tempStartMinutes;

        if (appointmentobject.Start.Minute.ToString().Length == 1)
        {
            tempStartMinutes = "0" + appointmentobject.Start.Minute.ToString();
        }
        else
        {
            tempStartMinutes = appointmentobject.Start.Minute.ToString();
        }

        tempStartDate = AppointmentObject.Start.Year + "-"
            + AppointmentObject.Start.Month + "-"
            + appointmentobject.Start.Day + " "
            + appointmentobject.Start.Hour + ":"
            + tempStartMinutes;

        string tempEndDate;
        string tempEndMinutes;

        if (appointmentobject.End.Minute.ToString().Length == 1)
        {
            tempEndMinutes = "0" + appointmentobject.End.Minute.ToString();
        }
        else
        {
            tempEndMinutes = appointmentobject.End.Minute.ToString();
        }

        tempEndDate = AppointmentObject.End.Year + "-"
            + AppointmentObject.End.Month + "-"
            + appointmentobject.End.Day + " "
            + appointmentobject.End.Hour + ":"
            + tempEndMinutes;

        //TODO Add CustomField : Need to add to this Insert Statement

        //Change the appointment subject
        string NewSubject = AppointmentObject.CustomFields["fldFirstName"]
            + ", " + AppointmentObject.CustomFields["fldLastName"]
            + ", " + AppointmentObject.CustomFields["fldClassID"]
            + ", " + AppointmentObject.CustomFields["fldPhoneNumberDay"];

        string mySQLQueryString = @"INSERT INTO appointment (StartDate,EndDate,Subject,Status,Description,label,location,Type,FirstName,
            LastName,PhoneNumberDay,PhoneNumberEvening,DriversLicenseNumber,Email,RentalCar,Payment,ConfirmationNumber,
            PermitNumber,ClassID,CreateDate,CreateUser,NoticeToReport) 
            VALUES('" + tempStartDate + "','"
            + tempEndDate + "', '"
            //+ AppointmentObject.Subject + "',"
            + NewSubject + "',"
            + AppointmentObject.StatusId + ",'"
            + AppointmentObject.Description + "',"
            + AppointmentObject.LabelId + ", '"
            + AppointmentObject.Location + "',"
            + "0, '" //type
            + AppointmentObject.CustomFields["fldFirstName"] + "','" 
            + AppointmentObject.CustomFields["fldLastName"] + "','"
            + AppointmentObject.CustomFields["fldPhoneNumberDay"] + "','"
            + AppointmentObject.CustomFields["fldPhoneNumberEvening"] + "','"
            + AppointmentObject.CustomFields["fldDriversLicenseNumber"] + "','"
            + AppointmentObject.CustomFields["fldEmail"] + "',"
            + AppointmentObject.CustomFields["fldRentalCar"] + ","
            + AppointmentObject.CustomFields["fldPayment"] + ",'"
            + AppointmentObject.CustomFields["fldConfirmationNumber"] + "','"
            + AppointmentObject.CustomFields["fldPermitNumber"] + "',"
            + AppointmentObject.CustomFields["fldClassID"] + ", '"
            //ignore create date for now.
            //+ AppointmentObject.CustomFields["fldCreateDate"] + "', '"
            + "2009-01-01 12:00', '"
            + AppointmentObject.CustomFields["fldCreateUser"] + "', "
            + AppointmentObject.CustomFields["fldNoticeToReport"] + ")";

        MySqlConnections test = new MySqlConnections();
        test.InsertRow(mySQLQueryString);

    }

public class MySqlConnections
{
    private static string DriverConnectionString = "Database=driverexam;Data Source=localhost;User Id=ART;Password=art01";

    public DataSet SelectRows(DataSet dataset, string query, string tablename)
    {
        MySqlConnection conn = new MySqlConnection(DriverConnectionString);

        MySqlDataAdapter adapter = new MySqlDataAdapter();
        adapter.SelectCommand = new MySqlCommand(query, conn);
        adapter.Fill(dataset, tablename);

        conn.Close();
        return dataset;
    }

    public bool InsertRow(string query)
    {
     //   MySqlConnection conn = new MySqlConnection(DriverConnectionString);

        MySqlConnection conn = new MySqlConnection();
        MySqlCommand cmd = new MySqlCommand();

        conn.ConnectionString = DriverConnectionString;

        try
        {
            conn.Open();
            cmd.Connection = conn;
            cmd.CommandText = query;
            cmd.ExecuteNonQuery();
            conn.Close();
            Console.WriteLine("Success Occurred ");
        } //end of try
        catch(Exception ex)
        {
            Console.WriteLine("Error Occurred - " + ex.Message);
        }

        return true;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM