Get Single Value By String MSSql


        public string GetSingleValueByString(string query, int column)
        {
            string value = "";

            try
            {
                _connector.OpenConnection();

                _command = new SqlCommand(query, _connector.Connect);
                _reader = _command.ExecuteReader();
                if (_reader.Read())
                {
                    value = _reader[column].ToString();
                }
                _reader.Close();
                _connector.CloseConnection();
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

            return value;

        }
  public bool IsDuplicate2Value(string tableName, string coloumName1, string value1)
        {
            string maxId = "";
            selectQuery = "SELECT " + coloumName1 + " FROM  " + tableName + " where " + coloumName1 + "=N'" + value1 + "'";
            maxId = GetSingleValueByString(selectQuery, 0);
            if (maxId == "")
            {
                return false;
            }
            return true;
        }

Comments

Popular posts from this blog

Provision AWS EC2 Instance and RDS with Terraform, and Deploy Spring Boot App to EC2 Instance via GitHub Action Pipeline

JQuery UI Autocomplete, custom HTML structure for result?

Easy Ui Jquery easyui-textbox change onChange event