当前位置: 首页>>代码示例>>C#>>正文


C# DbConnection.OpenConnection方法代码示例

本文整理汇总了C#中DbConnection.OpenConnection方法的典型用法代码示例。如果您正苦于以下问题:C# DbConnection.OpenConnection方法的具体用法?C# DbConnection.OpenConnection怎么用?C# DbConnection.OpenConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbConnection的用法示例。


在下文中一共展示了DbConnection.OpenConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: retrieveConversation

 public static ArrayList retrieveConversation(LoggedUser user, Host host)
 {
     ArrayList conversation = new ArrayList(new ArrayList());
     DbConnection db = new DbConnection();
     SqlConnection connection = db.OpenConnection();
     int conversation_id = 0;
     String query = "SELECT id FROM Conversation WHERE host=[email protected] AND [email protected]";
     SqlCommand command = new SqlCommand(query, connection);
     command.Parameters.AddWithValue("@host", host.loginName);
     command.Parameters.AddWithValue("@user", user.loginName);
     SqlDataReader reader = command.ExecuteReader();
     if (reader.Read())
     {
         conversation_id = reader.GetInt32(0);
     }
     db.CloseConnection();
     db.OpenConnection();
     String query1 = "SELECT id,content,initiator,message_read FROM Message WHERE [email protected]";
     SqlCommand command1 = new SqlCommand(query1, connection);
     command1.Parameters.AddWithValue("@id", conversation_id);
     SqlDataReader reader1 = command1.ExecuteReader();
     while (reader1.Read())
     {
         int id = reader1.GetInt32(0); 
         String message = reader1.GetString(1);
         String initiator = reader1.GetString(2);
         int read = reader1.GetInt32(3);
         ArrayList array = new ArrayList();
         array.Add(message); array.Add(initiator); array.Add(read); array.Add(id);
         conversation.Add(array);
     }
     db.CloseConnection();
     return conversation;
 }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:34,代码来源:MessageSystem.cs

示例2: saveImageInDb

    public Boolean saveImageInDb()
    {
        DbConnection db = new DbConnection();
        SqlConnection connection = db.OpenConnection();
        String query = "INSERT INTO Images (name, contentType, property, userLogin, data) VALUES (@name, @contentType, @property, @user, @data);";
        SqlCommand command = new SqlCommand(query, connection);
        command.Parameters.AddWithValue("@name", name);
        command.Parameters.AddWithValue("@contentType", contentType);
        if (propertyId != -1)
        {
            command.Parameters.AddWithValue("@property", propertyId);
        }
        else
        {
            command.Parameters.AddWithValue("@property", "NULL");
        }
        command.Parameters.AddWithValue("@user", user);
        command.Parameters.AddWithValue("@data", bytes);

        try
        {
            System.Diagnostics.Debug.Write(command.CommandText);
            command.ExecuteNonQuery();
            db.CloseConnection();
            return true;
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.Write(ex.Message);
            db.CloseConnection();
            return false;
        }
    }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:33,代码来源:Image.cs

示例3: checkUsername

 /**Check uniqness of username return ture if the username is unique*/
 public Boolean checkUsername(String loginName)
 {
     DbConnection db = new DbConnection();
     SqlConnection connection = db.OpenConnection();
     String query = "SELECT login FROM LoggedUser WHERE login = @login;";
     SqlCommand command = new SqlCommand(query, connection);
     command.Parameters.AddWithValue("@login", loginName);
     Object id = command.ExecuteScalar();
     if (id == null)
         return true;
     else
         return false;
 }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:14,代码来源:LoggedUser.cs

示例4: checkProperty

 /**Check if host has any properties to display in his profile*/
 public Boolean checkProperty(String loginName)
 {
     DbConnection db = new DbConnection();
     SqlConnection connection = db.OpenConnection();
     String query = "SELECT host FROM Property WHERE host = @loginName;";
     SqlCommand command = new SqlCommand(query, connection);
     command.Parameters.AddWithValue("@loginName", loginName);
     Object id = command.ExecuteScalar();
     db.CloseConnection();
     if (id == null)
         return false;
     else
         return true;
 }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:15,代码来源:Property.cs

示例5: checkLogin

 public Boolean checkLogin(String loginName, String password)
 {
     DbConnection db = new DbConnection();
     SqlConnection connection = db.OpenConnection();
     String query = "SELECT login FROM Host WHERE login = @login AND password = @password;";
     SqlCommand command = new SqlCommand(query, connection);
     command.Parameters.AddWithValue("@login", loginName);
     command.Parameters.AddWithValue("@password", password);
     Object id = command.ExecuteScalar();
     db.CloseConnection();
     if (id == null)
         return false;
     else
         return true;
 }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:15,代码来源:Host.cs

示例6: SignUp

 public Boolean SignUp(String loginName, String name, String email, String password)
 {
     DbConnection db = new DbConnection();
     SqlConnection connection = db.OpenConnection();
     String query = "INSERT INTO LoggedUser (login, name, email, password) VALUES (@login, @name, @email, @password);";
     SqlCommand command = new SqlCommand(query, connection);
     command.Parameters.AddWithValue("@login", loginName);
     command.Parameters.AddWithValue("@name", name);
     command.Parameters.AddWithValue("@email", email);
     command.Parameters.AddWithValue("@password", password);
     int row = command.ExecuteNonQuery();
     db.CloseConnection();
     if (row == 0)
         return false;
     else
         return true;
 }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:17,代码来源:LoggedUser.cs

示例7: createBooking

 public Boolean createBooking(LoggedUser loggedUser, Property property, String startDate, String endDate)
 {
     DbConnection db = new DbConnection();
     SqlConnection connection = db.OpenConnection();
     String query = "INSERT INTO Booking (start_date, end_date, loggedUser, property, status) VALUES (@startDate, @endDate, @user, @property, @status);";
     SqlCommand command = new SqlCommand(query, connection);
     command.Parameters.AddWithValue("@startDate", Convert.ToDateTime(startDate));
     command.Parameters.AddWithValue("@endDate", Convert.ToDateTime(endDate));
     command.Parameters.AddWithValue("@user", loggedUser.loginName);
     command.Parameters.AddWithValue("@property", property.propertyId);
     command.Parameters.AddWithValue("@status", "PENDING");
     int row = command.ExecuteNonQuery();
     if (row == 0)
         return false;
     else
         return true;
 }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:17,代码来源:Booking.cs

示例8: retrieveUsers

    public static ArrayList retrieveUsers(int conversationid)
    {
        ArrayList users = new ArrayList();
        DbConnection db = new DbConnection();
        SqlConnection connection = db.OpenConnection();

        String query1 = "SELECT host, loggedUser FROM Conversation WHERE [email protected]";
        SqlCommand command1 = new SqlCommand(query1, connection);
        command1.Parameters.AddWithValue("@id", conversationid);
        SqlDataReader reader1 = command1.ExecuteReader();
        while (reader1.Read())
        {
            String host = reader1.GetString(0);
            String user = reader1.GetString(1);
            Host h = Host.retrieveHost(host);
            LoggedUser u = LoggedUser.retrieveUser(user);
            users.Add(h);
            users.Add(u);
        }
        db.CloseConnection();
        return users;
    }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:22,代码来源:MessageSystem.cs

示例9: retrieveProperty

 public static Property retrieveProperty(String name)
 {
     Property property = new Property();
     DbConnection db = new DbConnection();
     SqlConnection connection = db.OpenConnection();
     String query = "SELECT * FROM Property WHERE name = @name;";
     SqlCommand command = new SqlCommand(query, connection);
     command.Parameters.AddWithValue("@name", name);
     SqlDataReader reader = command.ExecuteReader();
     while (reader.Read())
     {
         int id = reader.GetInt32(0);
         String locat = reader.GetString(2);
         int noRooms = reader.GetInt32(3);
         int noGuests = reader.GetInt32(4);
         double price = reader.GetDouble(5);
         String hostLoginName = reader.GetString(6);
         Host host = Host.retrieveHost(hostLoginName);
         property = new Property(id, name, locat, noRooms, noGuests, price, null, host);
     }
     db.CloseConnection();
     return property;
 }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:23,代码来源:Property.cs

示例10: getAcceptedBookings

 public static List<Booking> getAcceptedBookings(String userLogin)
 {
     List<Booking> booking = new List<Booking>();
     DbConnection db = new DbConnection();
     SqlConnection connection = db.OpenConnection();
     String query = "SELECT * FROM Booking WHERE status = 'ACCEPTED' AND DATEDIFF(DAY, GETDATE(), start_date) >= 0 AND loggedUser = @user";
     SqlCommand command = new SqlCommand(query, connection);
     command.Parameters.AddWithValue("@user", userLogin);
     SqlDataReader reader = command.ExecuteReader();
     while (reader.Read())
     {
         int id = reader.GetInt32(0);
         String start = reader.GetDateTime(1).ToShortDateString();
         String end = reader.GetDateTime(2).ToShortDateString();
         String user = reader.GetString(3);
         int propertyId = reader.GetInt32(4);
         String status = reader.GetString(5);
         LoggedUser loggedUser = LoggedUser.retrieveUser(user);
         Property property = Property.retrieveProperty(propertyId);
         booking.Add(new Booking(id, loggedUser, property, start, end, status));
     }
     db.CloseConnection();
     return booking;
 }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:24,代码来源:Booking.cs

示例11: getPendingBookings

 public static List<Booking> getPendingBookings(String hostLogin)
 {
     List<Booking> booking = new List<Booking>();
     DbConnection db = new DbConnection();
     SqlConnection connection = db.OpenConnection();
     String query = "SELECT * FROM Booking INNER JOIN Property ON Property.id = property WHERE Property.host = @host AND status = 'PENDING'";
     SqlCommand command = new SqlCommand(query, connection);
     command.Parameters.AddWithValue("@host", hostLogin);
     SqlDataReader reader = command.ExecuteReader();
     while (reader.Read())
     {
         int id = reader.GetInt32(0);
         String start = reader.GetDateTime(1).ToShortDateString();
         String end = reader.GetDateTime(2).ToShortDateString();
         String user = reader.GetString(3);
         int propertyId = reader.GetInt32(4);
         String status = reader.GetString(5);
         LoggedUser loggedUser = LoggedUser.retrieveUser(user);
         Property property = Property.retrieveProperty(propertyId);
         booking.Add(new Booking(id, loggedUser, property, start, end, status));
     }
     db.CloseConnection();
     return booking;
 }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:24,代码来源:Booking.cs

示例12: checkPendingBookedDates

 public static List<DateTime> checkPendingBookedDates(int propertyId)
 {
     DbConnection db = new DbConnection();
     SqlConnection connection = db.OpenConnection();
     List<DateTime> propDates = new List<DateTime>();
     int propCount = isPropertyExist(propertyId);
     if (propCount != 0)
     {
         DateTime propStartDate, propEndDate;
         String query = "SELECT start_date, end_date FROM Booking WHERE property = @propertyId AND status = 'PENDING';";
         SqlCommand command = new SqlCommand(query, connection);
         command.Parameters.AddWithValue("@propertyId", propertyId);
         SqlDataReader reader = command.ExecuteReader();
         while (reader.Read())
         {
             propStartDate = reader.GetDateTime(0);
             propEndDate = reader.GetDateTime(1);
             for (var date = propStartDate; date <= propEndDate; date = date.AddDays(1))
             {
                 propDates.Add(date);
             }
         }
     }
     else
     {
         db.CloseConnection();
         propDates = null;
     }
     db.CloseConnection();
     return propDates;
 }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:31,代码来源:Booking.cs

示例13: retrieveHost

 public static Host retrieveHost(String loginName)
 {
     Host result = new Host();
     DbConnection db = new DbConnection();
     SqlConnection connection = db.OpenConnection();
     String query = "SELECT * FROM Host WHERE login = @login;";
     SqlCommand command = new SqlCommand(query, connection);
     command.Parameters.AddWithValue("@login", loginName);
     SqlDataReader reader = command.ExecuteReader();
     while (reader.Read())
     {
         String name = reader.GetString(1);
         String email = reader.GetString(2);
         String password = reader.GetString(3);
         String contactNo = reader.GetString(4);
         result = new Host(1, loginName, name, email, password, contactNo);
     }
     db.CloseConnection();
     return result;
 }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:20,代码来源:Host.cs

示例14: searchByCompleteCriteria

 public List<Property> searchByCompleteCriteria(String location, double maxPrice, int noGuests)
 {
     List<Property> properties = new List<Property>();
     DbConnection db = new DbConnection();
     SqlConnection connection = db.OpenConnection();
     String query = "SELECT * FROM Property WHERE no_of_guests >= @numberGuests AND price <= @maxPrice AND location LIKE @location ORDER BY price ASC;";
     SqlCommand command = new SqlCommand(query, connection);
     command.Parameters.AddWithValue("@numberGuests", noGuests);
     command.Parameters.AddWithValue("@maxPrice", maxPrice);
     command.Parameters.AddWithValue("@location", "%" + location + "%");
     SqlDataReader reader = command.ExecuteReader();
     while (reader.Read())
     {
         int id = reader.GetInt32(0);
         String name = reader.GetString(1);
         String locat = reader.GetString(2);
         int noRooms = reader.GetInt32(3);
         int nuGuests = reader.GetInt32(4);
         double price = reader.GetDouble(5);
         String hostLoginName = reader.GetString(6);
         Host host = Host.retrieveHost(hostLoginName);
         properties.Add(new Property(id, name, locat, noRooms, nuGuests, price, null, host));
     }
     db.CloseConnection();
     return properties;
 }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:26,代码来源:Property.cs

示例15: searchProperty

 public List<Property> searchProperty(double maxPrice)
 {
     List<Property> properties = new List<Property>();
     DbConnection db = new DbConnection();
     SqlConnection connection = db.OpenConnection();
     String query = "SELECT * FROM Property WHERE price <= @maxPrice;";
     SqlCommand command = new SqlCommand(query, connection);
     command.Parameters.AddWithValue("@maxPrice", maxPrice);
     SqlDataReader reader = command.ExecuteReader();
     while (reader.Read())
     {
         int id = reader.GetInt32(0);
         String name = reader.GetString(1);
         String locat = reader.GetString(2);
         int noRooms = reader.GetInt32(3);
         int noGuests = reader.GetInt32(4);
         double price = reader.GetDouble(5);
         String hostLoginName = reader.GetString(6);
         Host host = Host.retrieveHost(hostLoginName);
         properties.Add(new Property(id, name, locat, noRooms, noGuests, price, null, host));
     }
     db.CloseConnection();
     return properties;
 }
开发者ID:AlexandraIoana,项目名称:CE903,代码行数:24,代码来源:Property.cs


注:本文中的DbConnection.OpenConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。