// считаем количество лайков для картинки или для поста public int GetLikeCount(int GroupID /*ImageID or PublicID*/, string GroupTableName /*Images or Publics*/) { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT IDinGroup FROM Like WHERE( GroupTableName=@GroupTableName ) and ( GroupID=@GroupID )"; // string queryString = "SELECT GroupID FROM Like";// WHERE( GroupTableName=@GroupTableName ) and ( GroupID=@GroupID )"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@GroupTableName", GroupTableName); //Select Parameter oCommand.AddSelectParam("@GroupID", GroupID); //Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); int likeCount = 0; while (reader.Read()) { likeCount++;// считаем количество лайков для картинки или для поста } oConnection.closeConnection(); return(likeCount); }
public int getMaxMessageID(int FromID, int ToID) { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT MessageID FROM Messages Where(FromUserID=@FromID) AND (ToUserID=@ToID)"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@FromID", FromID); //Select Parameter oCommand.AddSelectParam("@ToID", ToID); //Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); int max = 0; while (reader.Read()) { int id = Convert.ToInt32(reader[0]); if (max < id) { max = id; } } oConnection.closeConnection(); return(max); }
private void getNextMessagesIDs(int FromID, int ToID) { if (MessagesIDs == null) { MessagesIDs = new List <int>(); } SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT MessageID FROM Messages Where(FromUserID=@FromID) AND (ToUserID=@ToID)"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@FromID", FromID); //Select Parameter oCommand.AddSelectParam("@ToID", ToID); //Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); while (reader.Read()) { int id = Convert.ToInt32(reader[0]); MessagesIDs.Add(id);//считывание в массив юрэлов } counter = 0; oConnection.closeConnection(); }
public int GetImgCommentID(int ID, int imgID) { int returnVal = 0; SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT ImgCommentID FROM ImageComment Where (ID=@ID) AND (ImageID=@ImageID)"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@ID", ID); //Select Parameter oCommand.AddSelectParam("@ImageID", imgID); //Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); while (reader.Read()) { if ((reader[0] != null) && (!Convert.IsDBNull(reader[0]))) { returnVal = Convert.ToInt32(reader[0]);// } } oConnection.closeConnection(); return(returnVal); }
public bool isFriendsExist(int ID_1, int ID_2) { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; // string queryString = "SELECT ID FROM FriendTable" + " Where( (Friend_1_ID=@Fr_1) AND (Friend_2_ID=@Fr_2) ) or ( (Friend_1_ID=@Fr_2) AND (Friend_2_ID=@Fr_1) )"; string queryString = "SELECT ID FROM FriendTable Where( (Friend_1_ID=@Fr_1) AND (Friend_2_ID=@Fr_2) )"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@Fr_1", ID_1); //Select Parameter oCommand.AddSelectParam("@Fr_2", ID_2); //Select Parameter // oCommand.PrepareSelectQuery(queryString, oConnection.connection); SqlDataReader reader = oCommand.ExectuteReader(); bool returnValue = false; if (reader.Read()) { returnValue = true; //найдены друзья } oConnection.closeConnection(); return(returnValue); }
public string ReadePersonSurname(int dialogID, int messageID) { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT FromUserID FROM Messages Where (DialogID=@DialogID) and (MessageID = @MessageID)"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@DialogID", dialogID); //Select Parameter oCommand.AddSelectParam("@MessageID", messageID); //Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); int PersonID = 0; string PersonSurname = null; if (reader.Read()) { PersonID = Convert.ToInt32(reader[0]); } oConnection.closeConnection(); PeoplesClass oPeoples = new PeoplesClass(); PersonSurname = Convert.ToString(oPeoples.GetPeopleValue(PersonID, "Surname")); return(PersonSurname); }
public void getPeopleIDs(string name, string surname, string tableName) { if (PeopleIDs != null) { PeopleIDs = new List <int>();;//очищаем чтобы заполнить заново } SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT ID FROM " + tableName + " Where(Name=@Name) AND (Surname=@Surname)"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@Name", name); //Select Parameter oCommand.AddSelectParam("@Surname", surname); //Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); while (reader.Read()) { int id = Convert.ToInt32(reader[0]); PeopleIDs.Add(id);//считывание в массив юрэлов } counter = 0; oConnection.closeConnection(); }
public string ReadeDialogMessage(int dialogID, int messageID) { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT MessageText FROM Messages Where (DialogID=@DialogID) and (MessageID = @MessageID)"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@DialogID", dialogID); //Select Parameter oCommand.AddSelectParam("@MessageID", messageID); //Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); string messageText = null; if (reader.Read()) { messageText = Convert.ToString(reader[0]); } oConnection.closeConnection(); return(messageText); // listBox.Items.add }
/* * поиск людей которым пользователь когда либо писал */ public String GetMessageText(int FromID, int ToID, int messageID /*1....N*/) { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT MessageText FROM Messages Where(FromUserID=@FromID) and (ToUserID = @ToID) and (MessageID = @MesID) "; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@FromID", FromID); //Select Parameter oCommand.AddSelectParam("@ToID", ToID); //Select Parameter oCommand.AddSelectParam("@MesID", messageID); //Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); string messageText = null; if (reader.Read()) { messageText = Convert.ToString(reader[0]); } oConnection.closeConnection(); return(messageText); }
public int GetDialogID(int FirstPersonID, int SecondPersonID) //проверить { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT DialogID FROM Messages Where((FromUserID=@FirstID) and (ToUserID = @SecondID) ) or ( (FromUserID = @SecondID) and (ToUserID = @FirstID))"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@FirstID", FirstPersonID); //Select Parameter oCommand.AddSelectParam("@SecondID", SecondPersonID); //Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); int DialogID = -1; if (reader.Read()) { DialogID = Convert.ToInt32(reader[0]); } oConnection.closeConnection(); return(DialogID); }
public string readeImageURl(int ImageID, int PeopleID) //reade from database to List { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); string returnValue = null; // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT imgURL_Path FROM Images Where (ImageID = @ImageID) AND ( PeopleID=@PeopleID )"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@PeopleID", PeopleID); //Select Parameter oCommand.AddSelectParam("@ImageID", ImageID); //Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); while (reader.Read()) { returnValue = (reader[0] as string);//считывание в массив юрэлов } oConnection.closeConnection(); return(returnValue); }
public void readeImageURls(int UserID, string tableName) //reade from database to List { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); userID = UserID; // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT PeopleID, imgURL_Path FROM " + tableName + " Where PeopleID=@PeopleID"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@PeopleID", UserID);//Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); while (reader.Read()) { imageUrls.Add(reader[1] as string);//считывание в массив юрэлов } counter = 0; oConnection.closeConnection(); }
/// <summary> /// возвращает номера таблиц в которых содержатся номера друзей /// </summary> /// <param name="PeopleID"></param> /// <returns></returns> public List <int> GetFriendIDList(int PeopleID) { List <int> FriendListIDs = new List <int>();;//очищаем чтобы заполнить заново SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT ID FROM FriendTable Where(Friend_1_ID=@PeopleID) OR (Friend_2_ID=@PeopleID)"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@PeopleID", PeopleID);//Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); while (reader.Read()) { int id = Convert.ToInt32(reader[0]); FriendListIDs.Add(id);//считывание в массив юрэлов } oConnection.closeConnection(); return(FriendListIDs); }
/// <summary> /// Возвращает номер друга /// </summary> /// <param name="userID"></param> /// <param name="FriendListID"></param> /// <returns></returns> public int GetFriendID(int userID, int FriendListID) { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); int returnValue = 0; // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT Friend_1_ID, Friend_2_ID FROM FriendTable Where(ID=@FriendListID)"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@FriendListID", FriendListID);//Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); if (reader.Read()) { int FirstId = Convert.ToInt32(reader[0]); int SecondId = Convert.ToInt32(reader[1]); if (userID == FirstId) { returnValue = SecondId; } else { returnValue = FirstId; } } oConnection.closeConnection(); return(returnValue); }
public int getMaxMessageID(int dialogID) { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT MessageID FROM Messages Where (DialogID=@DialogID)"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@DialogID", dialogID);//Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); int maxID = 0; int messageID = 0; while (reader.Read()) { messageID = Convert.ToInt32(reader[0]); if (messageID > maxID) { maxID = messageID; } } oConnection.closeConnection(); return(maxID); }
public int GetMaxID(int ImageID) { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT ID FROM ImageComment Where ImageID=@ImageID"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@ImageID", ImageID);//Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); int maxID = -1;//если в таблице совсем нет записей int ID = 0; while (reader.Read()) { if ((reader[0] != null) && (!Convert.IsDBNull(reader[0]))) { ID = Convert.ToInt32(reader[0]);// if (maxID < ID) { maxID = ID; } } } oConnection.closeConnection(); return(maxID); }
public String GetMessageText(int MessageID)// этот метод удалить { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT MessageText FROM Messages Where(MessageID=@MessageID)"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@MessageID", MessageID);//Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); string messageText = null; if (reader.Read()) { messageText = Convert.ToString(reader[0]); } oConnection.closeConnection(); return(messageText); }
public object GetValueFromTableByIDName(int ID, string IDName, String ColumnName, string tableName) { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT " + ColumnName + " FROM " + tableName + " Where " + IDName + "=@ID "; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@ID", ID);//Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); object returnValue = null; if (reader.Read()) { returnValue = reader[0] as object; } oConnection.closeConnection(); return(returnValue); }
public int GetMaxIDInGroup(string IDName, string tableName, string GroupIDName, int GroupID) { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT " + IDName + " FROM " + tableName + " Where " + GroupIDName + "=@GroupID"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@GroupID", GroupID);//Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); int maxID = -1; while (reader.Read()) { int readVal = Convert.ToInt32(reader[0]); if (readVal > maxID) { maxID = readVal; } } oConnection.closeConnection(); return(maxID); }
public void readeImageIDs(int PeopleID, List <int> ImageIDsOut) { // ImageIDsOut = new List<int>(); SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT ImageID FROM Images Where PeopleID=@PeopleID"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@PeopleID", PeopleID);//Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); while (reader.Read()) { if (reader[0] != DBNull.Value) { ImageIDsOut.Add(Convert.ToInt32(reader[0]));//считывание в массив юрэлов } } oConnection.closeConnection(); }
protected void enter(object sender, EventArgs e)//почемуто не переходит на другую страницу { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT ID, Name, Surname, Phone, Password FROM Peoples Where Phone=@phone"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@phone", this.TextBox6.Text);//Для сравнения SqlDataReader reader = oCommand.ExectuteReader(); string phoneNumb; string Password; while (reader.Read()) { phoneNumb = reader[3] as string; //приведение типов Password = reader[4] as string; //приведение типов if (TextBox6.Text == phoneNumb) { //проверка логина if (TextBox5.Text == Password) //проверка пароля { //Запоминаем в куки файл Response.Cookies[ConstantNames.UserID].Value = Convert.ToString(reader[0]);//UserID to cookie Response.Cookies[ConstantNames.UserID].Expires = DateTime.Now.AddDays(1); // Response.Redirect("C:\Users\)_(\Documents\Visual Studio 2010\WebSites\WebSite5\main.aspx.cs"); Response.Redirect("Login.aspx"); } else { //Invalid password } } } /* * id = reader.GetValue(0); * name = reader.GetValue(1); * surname = reader.GetValue(2); * age = reader.GetValue(3); */ // cmdIns.Parameters.Add("@name", info); // cmdIns.ExecuteNonQuery();//выполнить команду oConnection.closeConnection(); }
public void SelectFromTable(List <TableValue> SelectedValues, List <TableValue> WhereValues, string TableName) { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string SelectString = null; string WhereString = null; foreach (TableValue element in SelectedValues) //Select Values { if (element == SelectedValues.ElementAt(SelectedValues.Count - 1)) //Если элемент последний то запятые не ставим { SelectString += element.ValueName; } else//Если элемент не последний то ставим запятые { SelectString += element.ValueName + ","; } } foreach (TableValue element in WhereValues) { if (element == WhereValues.ElementAt(WhereValues.Count - 1)) { WhereString += element.ValueName + "=@" + element.ValueName; } else { WhereString += element.ValueName + "=@" + element.ValueName + ",";//Where ID = @ID } } string queryString = "SELECT " + "(" + SelectString + ") FROM " + TableName + "(" + WhereString + " ) "; oCommand.PrepareSelectQuery(queryString, oConnection.connection); foreach (TableValue element in WhereValues) // WhereValues { oCommand.AddSelectParam("@" + element.ValueName, element.Value); //Add Select Parameter } SqlDataReader reader = oCommand.ExectuteReader(); object returnValue = null; if (reader.Read()) { returnValue = reader[0] as object; } oConnection.closeConnection(); }
public string selectImageCommentText(int ImageID, int ID) { string returnValue = null; SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT CommentPeopleID, Text FROM ImageComment Where (ID = @ID) AND (ImageID = @ImageID)"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@ImageID", ImageID); //Select Parameter oCommand.AddSelectParam("@ID", ID); //Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); if (reader.Read()) { int CommentPeopleID = Convert.ToInt32(reader[0]); PeoplesClass oPeople = new PeoplesClass(); string comPeopleSurname = oPeople.GetPeopleSurname(CommentPeopleID); string comPeopleName = oPeople.GetPeopleName(CommentPeopleID); string comText = Convert.ToString(reader[1]); returnValue = comPeopleSurname + comPeopleName + ": " + comText; //исключено что строка пустая } oConnection.closeConnection(); return(returnValue);//null если нет записей в таблице }
public void getToIDsByFromID(int FromID)//сначала надо вызвать это { //сюда записываем айдишника ToIDs = new List <int>(); //очищаем чтобы заполнить заново SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT ToUserID FROM Messages Where(FromUserID=@FromID)"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@FromID", FromID);//Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); while (reader.Read()) { int id = Convert.ToInt32(reader[0]); if (ToIDs.Count > 0) //не первый элемент { if (ToIDs.Last() != id) //если нет повторения { ToIDs.Add(id); //считывание в массив юрэлов } } else { ToIDs.Add(id);//записываем первый элемент } } this.ToIDCounter = 0; //установка в ноль счетчика. Поскольку ToIDs считываем заново oConnection.closeConnection(); }
public int GetCounterValue(int userID, string counterName) //работает строго с таблицей UserCounters { if (counterName == null) { return(-2);// не задана таблица. не корректные параметры } SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT userID, " + counterName + " FROM UserCounters where userID = @userID"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@phone", userID);//Для сравнения SqlDataReader reader = oCommand.ExectuteReader(); int UserID = 0; int counter = 0; UserID = Convert.ToInt32(reader[0]);//приведение типов counter = Convert.ToInt32(reader[1]); oConnection.closeConnection(); return(UserID); }
public int GetLikeCounterOfImage(int ImageID) { int likeCounter = 0; SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT LikeCounter FROM Images Where ( ImageID = @ImageID )"; /* * command.CommandText = "UPDATE Student(LastName, FirstName, Address, City) * VALUES (@ln, @fn, @add, @cit) WHERE LastName='" + lastName + * "' AND FirstName='" + firstName+"'"; */ oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@ImageID", ImageID);//Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); if (reader.Read()) { if (reader[0] != DBNull.Value) { likeCounter = Convert.ToInt32(reader[0]);//считывание в массив юрэлов } } return(likeCounter); oConnection.closeConnection(); }
public void readeSecondPersonIDs(int firstPersID) { SQLConnectionClass oConnection = new SQLConnectionClass(); SQLCommandClass oCommand = new SQLCommandClass(); SecondPersonIDs = new List <int>(); // string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; string queryString = "SELECT FromUserID, ToUserID FROM Messages Where(FromUserID=@FirstID) or (ToUserID = @FirstID)"; oCommand.PrepareSelectQuery(queryString, oConnection.connection); oCommand.AddSelectParam("@FirstID", firstPersID);//Select Parameter SqlDataReader reader = oCommand.ExectuteReader(); int FromID = 0; int ToID = 0; while (reader.Read()) { FromID = Convert.ToInt32(reader[0]); ToID = Convert.ToInt32(reader[1]); if (FromID == firstPersID) { bool isInteraction = false; for (int i = 0; i < SecondPersonIDs.Count; i++) { if (SecondPersonIDs.ElementAt(i) == ToID) { isInteraction = true;//чтобы не было повторений continue; } } if (!isInteraction) { SecondPersonIDs.Add(ToID); } } else { bool isInteraction = false; for (int i = 0; i < SecondPersonIDs.Count; i++) { if (SecondPersonIDs.ElementAt(i) == FromID) { isInteraction = true;//чтобы не было повторений continue; } } if (!isInteraction) { SecondPersonIDs.Add(FromID);//сообщение в обратную сторону } } } oConnection.closeConnection(); }