代码之家  ›  专栏  ›  技术社区  ›  Jaydel Gluckie

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

  •  1
  • Jaydel Gluckie  · 技术社区  · 17 年前

    我正在看一个ASP.net项目,他们想使用MySQL。我已经习惯使用SQL server,但使用mySQL应该不会有问题。

    通常情况下,控件希望绑定到SqlDataSource,但MySQL无法绑定到它(来自此站点上的其他帖子)。

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

    2 回复  |  直到 17 年前
        1
  •  3
  •   Rob Elsner    17 年前

    为什么不创建ObjectDataSource并编写数据层?或者使用LLBLGen,我认为它可以很好地与MySQL配合使用。我看到的一个警告是MySQL ODBC和ADO驱动程序在元数据方面存在问题。

        2
  •  1
  •   Jaydel Gluckie    17 年前

    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;
        }
    }
    
    推荐文章