如何在没有SqlDataSource的情况下将mysql连接到DevExpress ASPxScheduler

发布于 2024-07-10 21:37:08 字数 203 浏览 8 评论 0原文

我正在研究一个 ASP.net 项目,他们想使用 MySQL。 我习惯了 SQL Server,但使用 mySQL 应该不是问题。

通常,该控件需要绑定一个 SqlDataSource,但这对于 MySQL 来说不可用(来自本网站的其他帖子)。

连接 MySQL 和 DevExpress ASPxScheduler 以便创建约会的最佳方式是什么?

I have an ASP.net project I'm looking at and they want to use MySQL. I'm used to SQL server but using mySQL shouldn't be a problem.

Normally the control would like a SqlDataSource to bind to but that's not available with MySQL (from other posts on this site).

What's the best way to connect MySQL and the DevExpress ASPxScheduler so that you can create appointments?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

盗心人 2024-07-17 21:37:08

为什么不使用ObjectDataSource来写数据层呢? 或者使用 LLBLGen,我认为它与 MySQL 配合得很好。 我看到的一个警告是 MySQL ODBC 和 ADO 驱动程序存在元数据问题。

Why not an ObjectDataSource and write the data layer? Or use LLBLGen, I think it works just fine with MySQL. The one caveat I've seen is that the MySQL ODBC and ADO drivers have issues with metadata.

短叹 2024-07-17 21:37:08

我最终使用了 objectdatasource 和 ObjectCreated 方法,并编写了数据层以将记录插入 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;
    }
}

I did end up using the objectdatasource and the ObjectCreated method and wrote the datalayer to insert records into the mysql database. I've included my code just incase someone needs some help with some of the logic.

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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文